Use DB Link to synchronize tables between databases

Source: Internet
Author: User

Purpose

Use the create Database link statement to create a Database link. A database link is a schema object in a local database that can be used to access objects in a remote database. The remote database does not need to be an Oracle System.

Once a database link is created, you can use it to reference tables and views in a remote database. Add @ [dblink] after the table or view name to reference a remote table or view in an SQL statement. You can use the select statement to query remote tables or views. If you are using Oracle with distributed options, you can use any insert, update, delete, or lock table statements to access remote tables or views.

Prerequisites

To create a private Database link, you must have the create Database link system permission. To create a public Database link, you must have the create public Database link system permission. In addition, you must have the create session permission on the remote Oracle database.

Oracle Net must be installed on local and remote Oracle databases.

To access non-Oracle Systems, you must use Oracle Heterogeneous services (Oracle Heterogeneous Service ).

Syntax

CREATE [SHARED] [PUBLIC] database link dblink

Connect to [username identified by password authenticated_clause | CURRENT_USER]

USING 'string string'

Keywords and Parameters

Shared: specify that shared uses a separate network connection to create a public database link that can be shared by multiple users.

Public: create a public database link that can be used by all users. If this clause is omitted, the database link is private and can only be used by the creator.

Dblink: Specifies the full or partial name of the database link. The GLOBAL_NAMES initialization parameter determines whether the database link must have the same name as the database connected to the link.

The maximum number of database connections that can be opened by an instance in a session or real application cluster configuration depends on the value of the initialization parameters OPEN_LINKS and OPEN_LINKS_PER_INSTANCE.

Limitation: you cannot create a database link in another user's mode. You cannot use the mode name to limit dblink (". "character, so Oracle will be the full name, such as RALPH. LINKTOSALES refers to the name of the database link in the mode, rather than the LINKTOSALES database link in the RALPH mode.

Connect to clause: the connect to clause allows you to enable connection to a remote database.

CURRENT_USER clause: Use CURRENT_USER to create a database link for the current user. To make the connection successful, the current user must be a global user with a valid account on the remote database.

If you directly use a database link (not used from a storage object), the current user is the connected user.

When the database link is activated when a stored object (such as a process, view, or trigger) is executed, CURRENT_USER is the user name that owns the stored object, rather than the user name of the called object. For example, if the database link appears in SCOTT. P (created by SCOTT) and the user JANE calls SCOTT. P, the current user is SCOTT.

However, if the stored object is an invoker-right function, procedure, or package, the caller's authorization ID is used to connect as a remote user. For example, the database link appears in the process SCOTT. P (the caller's rights process created by SCOTT). If user JANE calls this process, CURRENT_USER is JANE and runs this process with JANE's permissions.

User identified by password: the user name and password used to connect to a remote database through a fixed user database link. If this clause is omitted, the database link uses the name and password of each user connected to the database (this is called the connection to the user database ).

Authenticated_clause: Specify the username and password of the target instance. This clause is required for user authentication on a remote server. The specified user name and password must be valid on the remote instance. The user name and password are only used for verification. Other operations cannot be performed in the name of this user.

This clause must be specified when the SHARED clause is used.

USING 'connect string': Specifies the service name of the remote database.

 

Example:

Create public database link erpsales
Connect to sales identified by sales
Using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.217.6) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = Alibaba sales)
)
)';

 

Host = IP address of the database

Service_name = the database ssid.

You can use NET8 easy config or directly modify the database connection string defined in TNSNAMES. ORA.

You can use the following command to check the global name of the database:

SELECT * FROM GLOBAL_NAME;

The @ dblink suffix can be omitted when a synonym can be created.

Create synonym name FOR table name;

Create synonym name FOR table name @ Database Link name;

 

Delete dblink: drop public database link dblink.

If you create a global dblink, you must use the mongom or sys user to add public to the database.

 

If the database needs to support Advanced replication, check whether it is supported by the following SQL statement:
Select * from v $ option where PARAMETER = 'advanced replicase ';

If True is returned, this parameter is supported.

Check whether the Global_name parameter is true or False.
Execute the statement: show parameter global_name;

If this parameter is set to true, the name of the locally created DBLINK must be the same as that of the remote Global_name.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.