DB Links or Database Links are used to connect mainly one database to another. It may be used to point to same database in some cases.
The information related to DB Link can be found from "DBA_DB_LINKS".
The syntax for db links is
SQL> Create [PUBLIC] database link "<Link_name>"
connect to <remote_dbuser> identified by <remoteuser_pasword>
using '<host>';
Here values in <> should be replaced by appropriate values.
1. Public option should be given with care. Without this the db_link will be accessible to only the user in which this is being created, but with public this can be used by all users in database.
2. The "host" is the entry you have in your TNSNAMES.ORA for remote database. There can also be kept the complete description in the db link syntax if we are not keeping the tns entry in tnsnames.ora for remote database.
e.g.
SQL> create database link "DBQA.XYZ.COM"
connect to "QA_USER" identified by "QA123"
using '(Description= (Address=(Protocol=tcp)(Host=192.168.127.23)(PORT=1522))(CONNECT_DATA=(SID=QADB))(HS=OK))';
To confirm if the dblink you created is working, just try..
SQL> Select * from dual@DBLINK_NAME;
This should show x as it always does on your database. You can also check if the database it is pointing to is correct (depends of remote user privileges).
SQL> Select name from v$database@DBLINK_NAME;
If the dblink is not working properly the command may show the error related to tns connection, or login etc.
The information related to DB Link can be found from "DBA_DB_LINKS".
The syntax for db links is
SQL> Create [PUBLIC] database link "<Link_name>"
connect to <remote_dbuser> identified by <remoteuser_pasword>
using '<host>';
Here values in <> should be replaced by appropriate values.
1. Public option should be given with care. Without this the db_link will be accessible to only the user in which this is being created, but with public this can be used by all users in database.
2. The "host" is the entry you have in your TNSNAMES.ORA for remote database. There can also be kept the complete description in the db link syntax if we are not keeping the tns entry in tnsnames.ora for remote database.
e.g.
SQL> create database link "DBQA.XYZ.COM"
connect to "QA_USER" identified by "QA123"
using '(Description= (Address=(Protocol=tcp)(Host=192.168.127.23)(PORT=1522))(CONNECT_DATA=(SID=QADB))(HS=OK))';
To confirm if the dblink you created is working, just try..
SQL> Select * from dual@DBLINK_NAME;
This should show x as it always does on your database. You can also check if the database it is pointing to is correct (depends of remote user privileges).
SQL> Select name from v$database@DBLINK_NAME;
If the dblink is not working properly the command may show the error related to tns connection, or login etc.
No comments:
Post a Comment