Data Guard是Oracle提供的一種高可用性解決方案,用於資料保護和容災,通過日誌同步來把資料及時傳送到備用節點,現總結一下Data Guard環境下常用的維護命令:
1、在生產庫停止Data Guard操作:
SQL> show parameter log_archive_dest
SQL> alter system set log_archive_dest_state_2=defer;
2、在生產庫開啟Data Guard操作:
SQL> alter system set log_archive_dest_state_2=enable;
3、在備份庫檢視生產庫傳過來的歸檔應用情況
SELECT FILE_NAME, SEQUENCE# AS SEQ#, FIRST_CHANGE# AS FCHANGE#,NEXT_CHANGE# AS NCHANGE#, TIMESTAMP,DICT_BEGIN AS BEG, DICT_END AS END,THREAD# AS THR# , APPLIED FROM DBA_LOGSTDBY_LOG ORDER BY THREAD#,SEQUENCE#;
4、在備份庫檢視應用事件
SELECT EVENT_TIME,EVENT,XIDUSN, XIDSLT, XIDSQN FROM DBA_LOGSTDBY_EVENTS order by 1 desc;
可跳過某些引起阻塞的DDL或DML應用,然後手工執行這些應用:
alter database stop logical standby apply;
exec dbms_logstdby.skip_transaction(14,21,517969);
ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE;
5、在備份庫跳過特定的DML或DDL操作
alter database stop logical standby apply;
execute dbms_logstdby.skip (stmt => 'DML', schema_name => 'BANPING',object_name => 'TABLENAME', proc_name => null);
alter database start logical standby apply;
由於oracle的bug,10203版本開始應用後會報以下錯誤:
ORA-00604: error occurred at recursive SQL level 1
ORA-01425: escape character must be character string of length 1
此時執行這個SQL語句可解決:
SQL> update system.logstdby$skip set esc = '\' where esc is NULL;
SQL> commit;
6、重新初始化表
alter database stop logical standby apply;
execute dbms_logstdby.unskip('DML','BANPING','TABLENAME');
exec dbms_logstdby.instantiate_table('BANPING','TABLENAME','dblink_name');
alter database start logical standby apply;
注意這裡建立的DBLINK dblink_name必須是public的,否則會報以下錯誤:
ORA-39001: invalid argument value
ORA-06512: at "SYS.DBMS_LOGSTDBY", line 577
ORA-06512: at line 1
7、在備庫檢視日誌應用狀態和進度:
select * from V$LOGSTDBY_STATE
select * from V$LOGSTDBY_PROGRESS
8、在備庫手動註冊歸檔日誌
SQL> ALTER DATABASE REGISTER LOGICAL LOGFILE '/stb_arch/1_143313_640266118.dbf';
Database altered.