如何实现两个数据库的同步

2024-11-10 20:31:20
推荐回答(3个)
回答(1):

这个算是最基本的数据库操作了,方案有很多种,常见的如:etl工具或使用dblink,etl工具比较方便,开源的产品有kettle,pdi等,这些产品可以满足大多数的数据库操作,但是如果数据量级大,转换复杂的话,他们的性能有待考验,不过你说的只是简单的同步,这个很容易。使用dblink也是比较常见的,但是需要设置一定机制,避免安全隐患,首先需要再A地数据库上配置B地数据库的远程连接地址,在tnsnames.ora文件中配置即可,然后在A地数据库上建立一个dblink,如:create database link b_to_a_link connect to xxx(user) identified by fundo using xxx(上面建立的连接);然后就可以操作了。

回答(2):

漳吊钩囟啥大中古

回答(3):

sql同步使用dblink同步数据。
具体参考实例:
1、在win下创建linux的DBLINK
a.查看linux下的tnsnames.ora文件
[oracle@myrac1 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /s01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
HJJ =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myrac1.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hjj)
)
)
b.创建dblink
SQL> create database link win_lin_link connect to hjj identified by xxxx
2 using '(DESCRIPTION =
3 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.171)(PORT = 1521))
4 (CONNECT_DATA =
5 (SERVER = DEDICATED)
6 (SERVICE_NAME = hjj)
7 )
8 )'
9 /
Database link created.
2.在win下创建trigger
SQL> create or replace trigger trig_win_emp
2 after insert on emp
3 for each row
4 begin
5 insert into emp@win_lin_link values(:new.empno,:new.empname,:new.empsalary);
6 end;
7 /
Trigger created.
3.测试
4.结果
win下插入数据
SQL> insert into emp values('E001','LYN',2300);
1 row created.
SQL>COMMIT;
Commit complete.
SQL> select *from emp;
EMPNO EMPNAME EMPSALARY
---------------------------------------- ---------------------------------------- ----------
E001 LYN 2300
SQL> select * from emp@win_lin_link;
EMPNO EMPNAME EMPSALARY
---------------------------------------- ---------------------------------------- ----------
E001 LYN 2300
linux下查看数据
SQL> select * from emp;
EMPNO EMPNAME EMPSALARY
-------------------- -------------------- ----------
E001 LYN 2300