Oracle11gR2_ADG管理之恢复主库的truncate表实战

Posted chinesern

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle11gR2_ADG管理之恢复主库的truncate表实战相关的知识,希望对你有一定的参考价值。

备库开启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

以上是关于Oracle11gR2_ADG管理之恢复主库的truncate表实战的主要内容,如果未能解决你的问题,请参考以下文章

Oracle11gr2_ADG管理之在备库上模拟failover的过程实战

ORACLE 11G 利用泠备份恢复standby库

ORACLE DG 日志传输的停止与恢复

oracle data guard备库备份恢复

Oracle 11.2.0.4.0 Dataguard部署和日常维护 - Dataguard Flashback

Oracle 11g Dataguard 暂停物理备库的日志传输