19c dml重定向使用
主库上执行
SQL>connect / as sysdba
SQL>alter session set container=pdb1;
SQL>create user hxl identified by oracle;
SQL>grant dba to hxl;
连接具体pdb
sqlplus /nolog
SQL> connect hxl/oracle@tnspdb1
Connected.
创建表
SQL> create table tb_test(id number,name varchar2(32));
Table created.
主库目前是没有数据的
SQL> select * from tb_test;
no rows selected
从库上执行
[oracle@19c admin]$ sqlplus /nolog
SQL> connect hxl/oracle@tns_slave_pdb1 ##从库的tns
Connected.
SQL> select * from tb_test;
no rows selected
SQL> show parameters adg_redirect_dml;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
adg_redirect_dml boolean FALSE
会话级别设置(会话退出后重新登录会失效)
SQL> alter session enable adg_redirect_dml;
Session altered.
insert into tb_test values(1,'name1');
insert into tb_test values(2,'name2');
insert into tb_test values(3,'name3');
从库查询:
SQL> select * from tb_test;
ID NAME
---------- --------------------------------
1 name1
2 name2
3 name3
主库查询:
SQL> select * from tb_test;
ID NAME
---------- --------------------------------
1 name1
2 name2
3 name3
发现从库上写入的数据已经同步到主库上