Oracle Database Links Survival Guide
Oracle Database Links Survival Guide
More Information can be found in the Oracle Distributed Database Management Guide
Overview
A database link is a schema object in one database that enables you to access objects on another
database. The other database need not be an Oracle Database system. However, to access non
Oracle systems you must use Oracle Heterogeneous Services.
Prerequisites
You must have the CREATE DATABASE LINK system privilege.
You must have the CREATE SESSION system privilege on the remote Oracle database.
You must be able to connect to the remote database.
Check GLOBAL_NAMES to setup the name of the database link.
DB_NAME
The DB_NAME parameter is the SID of the database and is the name used when creating the
database. It is specified within the INIT.ORA parameter file or in the CREATE DATABASE command.
DB_DOMAN
The DB_DOMAIN parameter is the value of the domain to which the database belongs. It can be the
same as defined in the DNS and is usually the company name. However you can set a DB_DOMAIN
value which is not part of the DNS.
GLOBAL_NAMES
GLOBAL_NAMES dictates how you might connect to a database. This variable is either TRUE or FALSE
and if it is set to TRUE it enforces database links to have the same name as the remote database to
http://www.akadia.com/services/ora_database_links.html 1/6
11/06/2015 Oracle Database Links Survival Guide
which they are connecting. Usually GLOBAL_NAMES is set to TRUE.
GENTIC.COMPANY.COM
So you have to set the database link name to GENTIC.COMPANY.COM if GLOBAL_NAMES is TRUE.
SQLNET
Setup your TNSNAMES.ORA so you can connect to the remote database.
GENTIC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = gentic.company.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = GENTIC.COMPANY.COM)
)
)
CELLAR =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cellar.company.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = CELLAR.COMPANY.COM)
)
)
sqlplus system/....@CELLAR
no rows selected
Synonym created.
no rows selected
http://www.akadia.com/services/ora_database_links.html 2/6
11/06/2015 Oracle Database Links Survival Guide
SQL> INSERT INTO scott.aTable(language, active, text) VALUES ('en',1,'english');
SQL> INSERT INTO scott.aTable(language, active, text) VALUES ('fr',1,'french');
SQL> INSERT INTO scott.aTable(language, active, text) VALUES ('it',1,'italian');
SQL> INSERT INTO scott.aTable(language, active, text) VALUES ('ru',0,'russian');
SQL> COMMIT;
As you can see, accessing the remote table is fully transparent to the application. Exactly
the same syntax can be used for the remote table if you create a synonym for the remote
table.
sqlplus system/....@CELLAR
PROCEDURE aProcedure
Synonym created.
As you can see, executing remote procedures is fully transparent to the application.
Exactly the same syntax can be used for the remote package if you create a synonym for
the remote package.
http://www.akadia.com/services/ora_database_links.html 3/6
11/06/2015 Oracle Database Links Survival Guide
The twophase commit mechanism ensures that all nodes either commit or perform a rollback
together. What happens if the transaction fails because of a system or network error? The transaction
becomes indoubt.
The RECO process automatically resolves indoubt transactions when the machine, network, or
software problem is resolved. Until RECO can resolve the transaction, the data is locked for both
reads and writes. Oracle blocks reads because it cannot determine which version of the data to
display for a query.
SQL> commit;
ERROR at line 1:
http://www.akadia.com/services/ora_database_links.html 4/6
11/06/2015 Oracle Database Links Survival Guide
ORA02054: transaction 1.37.5070 indoubt
ORA02068: following severe error from GENTIC
ORA03113: endoffile on communication channel
Now manually commit or rollback force the indoubt transaction as user SYS
SQL> exit;
sqlplus / as sysdba
Commit complete.
http://www.akadia.com/services/ora_database_links.html 5/6
11/06/2015 Oracle Database Links Survival Guide
establishes a connection to the remote database
as scott.
CREATE PUBLIC DATABASE LINK link_name A public link to the database with service name
CONNECT TO CURRENT_USER USING service. The link uses the userid/password of
'service'; the current user to log onto the remote
database.
CREATE PUBLIC DATABASE LINK link_name A public fixed user link. The link connects to the
CONNECT TO user IDENTIFIED BY ....; remote database with the userid/password.
http://www.akadia.com/services/ora_database_links.html 6/6