Oracle CREATE DATABASE LINK
Oracle CREATE DATABASE LINK
Once you create a database link, you can access the tables or views from the remote database using
the following pattern:
table_name@database_link
For example, you can query data from a table in the remote database as if it was in the local server:
When accessing a remote table or view over the database link, the Oracle database is acting as an
Oracle client.
And this query uses the synonym instead of the remote table name with the database link:
Private database links are visible to the owners while public database links are visible to all users in
the database. For this reason, public database links may pose some potential security risks.
To create a private database link, you use the CREATE DATABASE LINK statement as follows:
CREATE DATABASE LINK dblink
CONNECT TO remote_user IDENTIFIED BY password
USING 'remote_database';
In this syntax:
First, specify the name of the database link after the CREATE DATABASE LINK keywords.
Second, provide user and password of the remote database after the CONNECT
TO and IDENTIFIED BY keywords.
Finally, specify the service name of the remote database. If you specify only the database
name, Oracle will append the database domain to the connect string to form a complete service
name.
1. Naming convention: the name of the database links should reflect the nature of data, not the
database server. For example, instead of naming a database link SALES_PRD, you name it
as SALES.
2. Remote database users: you should create a user dedicated for a database link. In addition,
you should not give this user to anyone else. If you don’t follow this, the database will not work
when someone changes the password of the user or even delete it.
3. Use a service-specific entry in the tnsnames.ora instead of the database-specific alias so that
you copy between product, test, and development environments, you don’t have to recreate the
database link.