Friday, September 26, 2008

Oracle DB links

Here are the steps to create Db links from one database to another database.
I am creating a database link in SRITSTDB(source db) for schema/user "TEST" to SRISTGDB(target db).

Step 1: Adding a TNS entry for target db in source db host machine.

     a) Open tnsnames.ora file in SRITSTDB database.
          It will be located in $ORACLE_HOME/network/admin
     b) add the tns entry like below.
          "SRISTGDB = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hello)(PORT=1521))
          (CONNECT_DATA=(SID=SRISTGDB)))"

Step 2: Login as user in which you want to create this db link.

     Here I mentioned for TEST user. So i am logging as "TEST" user as below.
     UNIX PROMPT>sqlplus test/test)))"


Step 3: Creating a database link.
Use the below sql to create the syntax.
Syntax: Create database link linkname connect to user identified by pwd using 'CONEECT_STRING';
Usage 1:Create database link SRISTGDBLINK CONNECT to test identified by test
               using 'SRISTGDB';
Note: If there is any problem in TNS setup on that host use the follwing method to create the db link. I am using the complete connect string descriptor instead of just connect string name. Some times If you are trying to use this db link from sql navigator or from sql*plus it will give "ORA-12541: TNS: no listener". For that use the follwing syntax to create the dblink.
Usage 2:Create database link SRISTGDBLINK CONNECT to test identified by test using '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hello)(PORT=1521))(CONNECT_DATA=(SID=SRISTGDB)))';


Step 4: Checking.
     a) Connect as TEST user to the SRITSTDB.
     b) select name from v$database@SRISTGDBLINK;

No comments:

Followers