备库开启flashback database
#关闭备库的同步
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> alter database flashback on;
Database altered.
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
SQL> alter database recover managed standby database using current logfile disconnect;
Database altered.
查看同步状态,备库实时应用主库的归档
#主库上执行
SQL> set linesize 300
SQL> col DESTINATION format a10
SQL> col db_unique_name format a10
SQL> col database_mode format a20
SQL> col recovery_mode format a20
SQL> col synchronization_status format a10
SQL> col gap_status format a10
SQL> SELECT DESTINATION,db_unique_name,type,STATUS,database_mode,recovery_mode,ARCHIVED_THREAD#,ARCHIVED_SEQ#,applied_seq#,synchronization_status,gap_status FROM V$ARCHIVE_DEST_STATUS WHERE STATUS <> 'DEFERRED' AND STATUS <> 'INACTIVE';
DESTINATIO DB_UNIQUE_ TYPE STATUS DATABASE_MODE RECOVERY_MODE ARCHIVED_THREAD# ARCHIVED_SEQ# APPLIED_SEQ# SYNCHRONIZ GAP_STATUS
---------- ---------- -------------- --------- -------------------- -------------------- ---------------- ------------- ------------ ---------- ----------
NONE LOCAL VALID OPEN IDLE 1 44 0 CHECK CONF
IGURATION
snewtest snewtest PHYSICAL VALID OPEN_READ-ONLY MANAGED REAL TIME AP 1 44 43 CHECK CONF NO GAP
PLY IGURATION
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
4410236
主库发生误操作将表test truncate 掉
SQL> truncate table test;
Table truncated.
SQL> select count(*) from test;
COUNT(*)
----------
0
#记录scn
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
-----------
4410383
#通过logminer搜索一定范围内的archivelog,确定drop操作对应的准确SCN号
SQL> exec dbms_logmnr.start_logmnr(startscn=>4410236,endscn=>4410383,options=>DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG + DBMS_LOGMNR.CONTINUOUS_MINE);
PL/SQL procedure successfully completed.
SQL> col sql_redo format a110
SQL> set linesize 180
SQL> select scn,sql_redo,timestamp from v$logmnr_contents where table_name='TEST';
SCN SQL_REDO TIMESTAMP
---------- -------------------------------------------------------------------------------------------------------------- ---------
4410319 truncate table test;
#确定flashback database的目标时间为4410319
在备库上执行flashback database
SQL> select count(*) from test;
COUNT(*)
----------
0
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> flashback database to scn 4410236;
Flashback complete.
SQL> alter database open read only;
Database altered.
SQL> select count(1) from test;
COUNT(1)
----------
23
使用dblink或者datapump将数据恢复到主库上
:
create public database link system_snewtest connect to sys identified by "oracle" using ‘snewtest‘;
insert into test select * from [email protected]_snewtest;
SQL> select count(1) from test;
COUNT(1)
----------
23
重新开启备库上的MRP
SQL> alter database recover managed standby database using current logfile disconnect ;
Database altered.
SQL> select count(1) from test;
COUNT(1)
----------
2
原文地址:https://www.cnblogs.com/chinesern/p/8687107.html
时间: 2024-11-14 12:30:18