Vous êtes sur la page 1sur 6

############################################################## PUBLIC Specify PUBLIC to create a public database link visible to all users.

If you omi t this clause, then the database link is private and is available only to you. The data accessible on the remote database depends on the identity the database link uses when connecting to the remote database: If you specify CONNECT TO user IDENTIFIED BY password, then the database lin k connects with the specified user and password. If you specify CONNECT TO CURRENT_USER, then the database link connects with the user in effect based on the scope in which the link is used. If you omit both of those clauses, then the database link connects to the re mote database as the locally connected user ############################################################## SHARED Specify SHARED to create a database link that can be shared by multiple sessions using a single network connection from the source database to the target databa se. In a shared server configuration, shared database links can keep the number of connections into the remote database from becoming too large. Shared links ar e typically also public database links. However, a shared private database link can be useful when many clients access the same local schema, and therefore use the same private database link. In a shared database link, multiple sessions in the source database share the sa me connection to the target database. Once a session is established on the targe t database, that session is disassociated from the connection, to make the conne ction available to another session on the source database. To prevent an unautho rized session from attempting to connect through the database link, when you spe cify SHARED you must also specify the dblink_authentication clause for the users authorized to use the database link. ############################################################## dblink Specify the complete or partial name of the database link. If you specify only t he database name, then Oracle Database implicitly appends the database domain of the local database. Use only ASCII characters for dblink. Multibyte characters are not supported. Th e database link name is case insensitive and is stored in uppercase ASCII charac ters. If you specify the database name as a quoted identifier, then the quotatio n marks are silently ignored. If the value of the GLOBAL_NAMES initialization parameter is TRUE, then the data base link must have the same name as the database to which it connects. If the v alue of GLOBAL_NAMES is FALSE, and if you have changed the global name of the da tabase, then you can specify the global name. The maximum number of database links that can be open in one session or one inst ance of an Oracle RAC configuration depends on the value of the OPEN_LINKS and O PEN_LINKS_PER_INSTANCE initialization parameters. ############################################################## CURRENT_USER Clause

Specify CURRENT_USER to create a current user database link. The current user mu st be a global user with a valid account on the remote database. If the database link is used directly rather than from within a stored object, t hen the current user is the same as the connected user. When executing a stored object (such as a procedure, view, or trigger) that init iates a database link, CURRENT_USER is the name of the user that owns the stored object, and not the name of the user that called the object. For example, if th e database link appears inside procedure scott.p (created by scott), and user ja ne calls procedure scott.p, then the current user is scott. ############################################################## ############################################################## A database link is a schema object in one database that enables you to access ob jects on another database ############################################################### test dblink on two vmware linux machines ############################################################## before start work on oracle first both os machines should be pinging by their ip address or their hostname ############################################################## after pinging correctly work on network adapter on both machine check that liste ner is working correctly ############################################################## this is my listener.ora file for firstvmware machine ############################################################## SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1) (PROGRAM = extproc) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.20)(PORT = 1521)) ) ) ############################################################## this is my listener.ora configuration for second vmware machine ############################################################## SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1) (PROGRAM = extproc) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rhel.oracle.com)(PORT = 1522))

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) ) ############################################################## this is my tnsnames.ora configuration for first machine ############################################################## PROD = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oracle.data.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prod) ) ) SAP = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rhel.oracle.com)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = SAP) ) ) EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) ) ############################################################## this is my tnsnames.ora configuration for second machine ############################################################## PROD = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oracle.data.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = prod) ) ) SAP = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rhel.oracle.com)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = SAP) ) ) EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) ) ############################################################## in tha above tnsnmaes.ora files i have added my tns entry my first machine db na me id prod and second machine db name is sap. ############################################################## after this check is using tnsping utility tnsping prod tnsping sap on both machines. ############################################################## It worked correctly now create dblink create database link testlink_db2 connect to system identified by oracle using s ap; or create database link testlink_db2 connect to system identified by oracle using ' (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=rhel.oracle.com) (PORT=1522)) (CONN ECT_DATA= (SERVER = DEDICATED) (SERVICE_NAME = SAP)))'; select * from v$version@testlink_db2; worked correctly perfect ############################################################## create database link testlink_db2 connect to system identified by oracle using p rod; or create database link testlink_db2 connect to system identified by oracle using ' (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=oracle.data.com) (1521)) (CONNECT_DATA= (SERVER = DEDICATED) (SERVICE_NAME = prod)))'; select * from v$version@testlink_db2; ############################################################## CREATE SYNONYM net FOR system.link@testlink_db2; ############################################################## u can insert,update,delete using dblink but can't ddl operation are not allowed on remote database ############################################################## using system user create table in second machine and insert values on it and usi ng dblink acces this table from first machine; ############################################################## on sap machine SQL>conn system/oracle; SQL>create table link (id number(8)); SQL>insert into link (5); on prod machine SQL>insert into link@testlink_db2 values(6); SQL>select * from link@testlink_db2; ID ---6 on SAP machine SQL>select * from link; no rows found; on prod machine SQL>commit;

then works on sap machine SQL>select * from link; ID ---6 ############################################################## first set format for better output ############################################################## set linesize 121 col db_link format a20 col username format a20 col password format a20 col host format a20 ############################################################## Related Data Dictionary Objects link$ all_db_links gv_$session_connect_info repcat$_repprop_dblink_how dba_db_links ku$_dblink_t user_db_links dbms_dblink ku$_dblink_view wmp_api_dblink dbms_dblink_lib ku$_10_1_dblink_view wmp_db_links_v gv_$dblink ora_kglr7_db_links ############################################################## Related Files $ORACLE_HOME/rdbms/admin/caths.sql System Privileges create database link create public database link drop public database link ############################################################## current_user link ############################################################## CREATE DATABASE LINK curr_user CONNECT TO CURRENT_USER USING 'conn_link'; ############################################################## fixed_user link ############################################################## CREATE DATABASE LINK fixed_user CONNECT TO hr IDENTIFIED BY hr USING 'conn_link'; SELECT DISTINCT sid FROM gv$mystat; SELECT authentication_type, osuser, network_service_banner FROM gv$session_connect_info WHERE sid = 143; SELECT table_name, tablespace_name FROM user_tables@fixed_user; ############################################################## shared db link ############################################################## CREATE SHARED DATABASE LINK shared CONNECT TO scott IDENTIFIED BY tiger AUTHENTICATED BY uwclass IDENTIFIED BY uwclass USING 'conn_link'; ############################################################## public link ############################################################## conn / as sysdba

CREATE PUBLIC DATABASE LINK publink USING 'conn_link'; SELECT * FROM dba_db_links; conn scott/tiger SELECT table_name, tablespace_name FROM user_tables@publink; conn sh/sh SELECT table_name, tablespace_name FROM user_tables@publink; conn uwclass/uwclass SELECT table_name, tablespace_name FROM user_tables@publink; ############################################################## close database link ################### ALTER SESSION CLOSE DATABASE LINK curr_user; ############################################################## drop database link ################## drop database link tes4; drop public database link tes4; ############################################################## SELECT NAME,HOST,USERID,PASSWORD FROM SYS.LINK$; ############################################################## ##############################################################

Vous aimerez peut-être aussi