1.更新被重定向到主库
2.在主库上更新后,生成并发送该更新到备库
3.重定向更新在提交之前仅对会话可见,提交后对所有会话可见,满足ACID的要求
要启用这个功能,需满足一下几点
1.不能是sys或system等common user
2.使用SRL(standby redo logfile)
3.如果使用了CDB,要确保主库所有的PDB处于read write状态,备库所有PDB处于read only状态
4.备库必须启用real time apply
如何开启DML Redirect
控制该功能的初始化参数是ADG_REDIRECT_DML,我们可以在会话级别或数据库级别设置
会话级别
SQL> alter session enable adg_redirect_dml;
数据库级别
SQL> alter system set adg_redirect_dml=true scope=both;
测试DML Redirect
SQL> select database_role,open_mode from v$database;
SQL> alter session enable adg_redirect_dml;
如果在此时我们禁用adg_redirect_dml,插入数据就会报错
异常情况和解决办法
常见的错误代码是ORA-16397,我们也可以看下Oracle的官方解释,可根据实际情况,适当调整
[oracle@xd08mdb01 ~]$ oerr ora 1639716397, 00000, "statement redirection from Oracle Active Data Guard standby database to primary database failed"
// *Cause: The statement redirection failed because of one of the following reasons:
// 1. The primary database connect string was not established.
// 2. The primary database could not be reached.
// 3. The undo-mode or incarnation were not the same.
// 4. The current user and logged-in user were not the same.
// 5. Redirecting CREATE TABLE AS SELECT (CTAS) of the global temporary
// table was not supported.
// 6. Redirecting PL/SQL execution having bind variable was not supported.
// *Action: Run the statement after fixing the condition that caused the failure.
[oracle@xd08mdb01 ~]$
如果要执行CREATE TABLE等操作,需求启用adg_redirect_plsql
alter session enable adg_redirect_plsql;
begin
execute immediate 'create table test (a number)';
end;
/
Reference
https://docs.oracle.com/en/database/oracle/oracle-database/19/sbydb/managing-oracle-data-guard-physical-standby-databases.html#GUID-8AAD002C-ED06-4349-8BB5-EC8DB30B2628
https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/ADG_REDIRECT_DML.html#GUID-AC98F026-33BE-41FE-8F2F-EFA296723AD8