DB_LINK创建
Machine 1:
IP:10.80.18.241
Machine 2:
IP:10.80.18.245
1.在Machine 2的数据库中增加用户
以oracle用户登录Machine 2
$sqlplus / as sysdba
SQL>create user test identified by test;
User created.
SQL>grant connect,resource to test;
Grant succeeded.
2.修改Machine 1的tnsnames.ora文件
增加如下内容:
scofy =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.80.18.245)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = scofy)
)
)
3.创建db link
以oracle用户登录Machine 1
$sqlplus / as sysdba
SQL>create public database link prepaid_test connect to test identified by test using 'scofy';
Database link created.
SQL>show parameter global_names
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
global_names boolean TRUE
SQL>select * from dual@prepaid_test;
select * from dual@prepaid_test
*
ERROR at line 1:
ORA-02085: database link PREPAID_TEST connects to PREPAID
SQL>alter system set global_names=false;
System altered.
SQL>select * from dual@prepaid_test;
D
-
X
可以看到,当global_names=false时,db link可以连接远程数据库。
当global_names=true时,如果创建的db link名字与远程数据库的实例名一致,还是可以访问的。