Pages

Tuesday, November 18, 2014

DBLINKs in Oracle Streams Environment

DB LINKs in Oracle Streams Environment

When working in Oracle Streams Environment, the parameter GLOBAL_NAMES must be set to TRUE.

SELECT * FROM GLOBAL_NAME;
GLOBAL_NAME
-----------
ORADB1


SELECT name, value 
FROM V$PARAMETER WHERE name like '%global%';
NAME            VALUE
--------------- ----------
global_names    TRUE

Limitation for naming the database link
When GLOBAL_NAMES is set to true, the name of the DBLINK must be the same as the name of the database!

Per Oracle documentation, the name of the database link should match the global name of the target database if GLOBAL_NAMES=TRUE. 

This seems to be very restricting since then there can be only one database link per schema to a given database, if global_names is set to true. 
To overcome this limitation need to use database link qualifiers. 

Database Link Qualifiers
The syntax is: dblink@dbqualifier

For example: 
CREATE DATABASE LINK oradb1@link1 USING 'conn_str1'; 
CREATE DATABASE LINK oradb1@link2 USING 'conn_str2'; 

And the application, should use below code:
SELECT SYSDATE FROM DUAL@oradb1@link1;

To make the code more robust, create SYNONYMS for the remote objects, and have the application use the synonym name.

CREATE SYNONYM TABLE_1 FOR TABLE_1@oradb1@link1;
CREATE SYNONYM TABLE_2 FOR TABLE_2@oradb1@link2;

ORA-02085
What happens if you create a database link with name other than  the value of GLOBAL_NAME?
You get ORA-02085 - database link string connects to string
Cause:  A database link connected to a database with a different name. 
              The connection is rejected.
Action: Create a database link with the same name as the database it connects to, 
               or set global_names=false.

No comments:

Post a Comment