• oracle 11g adg 归档文件丢失(主库也找不到归档)


    环境,前面的dg的测试环境,主库cad,备库cad02

    在一段时间之后,启动备库失败(open)

    [oracle@dg1 ~]$ export ORACLE_SID=cad02
    [oracle@dg1 ~]$ sqlplus /nolog
    SQL> conn /as sysdba
    SQL> startup mount;
    SQL> ALTER DATABASE OPEN;
    ALTER DATABASE OPEN
    *
    ERROR at line 1:
    ORA-10458: standby database requires recovery
    ORA-01196: file 1 is inconsistent due to a failed media recovery session
    ORA-01110: data file 1:
    '/u01/app/oracle/oradata/cad02/data/system.271.1032629567'
    [oracle@dg1 ~]$ lsnrctl start
    SQL> alter database recover managed standby database disconnect from session;
    
    Database altered.
    
    SQL> select process,status,sequence#,delay_mins from v$managed_standby;
    
    PROCESS   STATUS    SEQUENCE# DELAY_MINS
    --------- ------------ ---------- ----------
    ARCH      CONNECTED        0       0
    ARCH      CONNECTED        0       0
    ARCH      CLOSING          488       0
    ARCH      CONNECTED        0       0
    RFS      CLOSING          567       0
    RFS      CLOSING          565       0
    RFS      CLOSING          566       0
    RFS      CLOSING          301       0
    RFS      IDLE              621       0
    RFS      CLOSING          299       0
    RFS      CLOSING          300       0
    
    PROCESS   STATUS    SEQUENCE# DELAY_MINS
    --------- ------------ ---------- ----------
    RFS      WRITING          382       0
    MRP0      WAIT_FOR_GAP          241       0 ###WAIT_FOR_GAP注意此状态
    
    13 rows selected.

    查询归档

    SQL>  select max(sequence#) from v$archived_log; ##已经同步到最新的归档日志
    
    MAX(SEQUENCE#)
    --------------
           621
    
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; ##但是由于缺少之前的归档,报错
    
    Database altered.
    
    SQL> alter database open;
    alter database open
    *
    ERROR at line 1:
    ORA-10458: standby database requires recovery
    ORA-01196: file 1 is inconsistent due to a failed media recovery session
    ORA-01110: data file 1:
    '/u01/app/oracle/oradata/cad02/data/system.271.1032629567'
    
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;
    
    Database altered.
    
    SQL> select thread#,low_sequence#,high_sequence# from v$archive_gap; ##查询到有归档缺失
    
       THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
    ---------- ------------- --------------
         2         241        244

    查询备库当前的归档日志状态

    col name for a100
    set linesize 9999  pagesize 9999
    SQL> SELECT dest_id,THREAD#,NAME,sequence#,archived,applied,a.NEXT_CHANGE#
    FROM   v$archived_log a
    WHERE  a.sequence# >= 200
    AND    resetlogs_change# = (SELECT d.RESETLOGS_CHANGE# FROM v$database d)
    and a.dest_id=1
    ORDER  BY a.THREAD#,
    a.sequence#,a.dest_id;  2    3    4    5    6    7  
    
       DEST_ID    THREAD# NAME                                                                                    SEQUENCE# ARC APPLIED     NEXT_CHANGE#
    ---------- ---------- ---------------------------------------------------------------------------------------------------------------------------------------
         1        1 /u01/app/oracle/archive/1_488_1032629558.arch                                                                      488 YES NO         12496347
         1        1 /u01/app/oracle/archive/1_621_1032629558.arch                                                                      621 YES NO         17879615
         1        1 /u01/app/oracle/archive/1_622_1032629558.arch                                                                      622 YES NO         17917819
         1        2 /u01/app/oracle/archive/2_382_1032629558.arch                                                                      382 YES NO         17879589
         1        2 /u01/app/oracle/archive/2_383_1032629558.arch                                                                      383 YES NO         17879605
         1        2 /u01/app/oracle/archive/2_384_1032629558.arch                                                                      384 YES NO         17879625
    
    6 rows selected.   

    主库,拿到scn号去增量备份

    SQL> set linesize 999
    SQL> select dbid,current_scn,protection_mode,protection_level,database_role,force_logging,open_mode,switchover_status from v$database;
    
          DBID      CURRENT_SCN PROTECTION_MODE      PROTECTION_LEVEL       DATABASE_ROLE    FOR OPEN_MODE         SWITCHOVER_STATUS
    ---------- - ----------- -------------------- -------------------- ---------------- --- -------------------- --------------------
    1640682678       17922067 MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  PRIMARY        YES READ WRITE         UNRESOLVABLE GAP
    SQL> archive log list;
    Database log mode           Archive Mode
    Automatic archival           Enabled
    Archive destination           +FRA
    Oldest online log sequence     622
    Next log sequence to archive   623
    Current log sequence           623
    
    SELECT dest_id,THREAD#,NAME,sequence#,archived,applied,a.NEXT_CHANGE#
    FROM   v$archived_log a
    WHERE  a.sequence# >= 200
    AND    resetlogs_change# = (SELECT d.RESETLOGS_CHANGE# FROM v$database d)
    and a.dest_id=1
    ORDER  BY a.THREAD#,
    a.sequence#,a.dest_id;
    
    
    SELECT (SELECT MIN(d.CHECKPOINT_CHANGE#) FROM v$datafile d) datafile_scn,
           (SELECT MIN(d.CHECKPOINT_CHANGE#)
            FROM   v$datafile_header d
            WHERE  rownum = 1) datafile_header_scn,
           (SELECT current_scn FROM v$database) current_scn,
           (SELECT b.NEXT_CHANGE#
            FROM   v$archived_log b
            WHERE  b.SEQUENCE# = 240
            AND    resetlogs_change# =
                   (SELECT d.RESETLOGS_CHANGE# FROM v$database d)
            AND    rownum = 1) NEXT_CHANGE#
    FROM   dual;

    主库rman备份

    [oracle@rac01 standby_bk]$ rman target/
    
    Recovery Manager: Release 11.2.0.4.0 - Production on Wed May 6 16:04:48 2020
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    
    RMAN> run
    {
    allocate channel d1 type disk;
    allocate channel d2 type disk;
    backup as compressed backupset incremental from SCN 17879625 database format '/home/oracle/standby_bk/standby_%d_%T_%U.bak' include current controlfile for standby filesperset=5  tag 'FOR 2> 3> 4> 5> STANDBY';
    release channel d1;
    release channel d2;
    }6> 7> 8>
    [oracle@rac01 standby_bk]$ ll
    total 16848
    -rw-r----- 1 oracle asmadmin 11345920 May  6 16:08 standby_20200506_07uvhd04_1_1.bak
    -rw-r----- 1 oracle asmadmin  4775936 May  6 16:07 standby_20200506_08uvhd0c_1_1.bak
    -rw-r----- 1 oracle asmadmin  1130496 May  6 16:08 standby_20200506_09uvhd2k_1_1.bak
    把增量备份拷贝到备库
    [oracle@rac01 standby_bk]$ pwd
    /home/oracle/standby_bk
    [oracle@rac01 standby_bk]$ scp * oracle@*:/home/oracle/standby_bk/.
    oracle@1*'s password: 
    standby_20200506_07uvhd04_1_1.bak                                                                                                                     100%   11MB  10.8MB/s   00:00    
    standby_20200506_08uvhd0c_1_1.bak                                                                                                                     100% 4664KB   4.6MB/s   00:00    
    standby_20200506_09uvhd2k_1_1.bak                                                                                                                     100% 1104KB   1.1MB/s   00:00    
    备库查询
    [oracle@dg1 ~]$ mkdir -p /home/oracle/standby_bk
    [oracle@dg1 ~]$ cd standby_bk/
    [oracle@dg1 standby_bk]$ ll
    total 16848
    -rw-r----- 1 oracle oinstall 11345920 May  6 16:14 standby_20200506_07uvhd04_1_1.bak
    -rw-r----- 1 oracle oinstall  4775936 May  6 16:14 standby_20200506_08uvhd0c_1_1.bak
    -rw-r----- 1 oracle oinstall  1130496 May  6 16:14 standby_20200506_09uvhd2k_1_1.bak

    重启备库到nomount

    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
    
    Database altered.
    
    SQL> shutdown immediate;
    ORA-01109: database not open
    
    
    Database dismounted.
    ORACLE instance shut down.
    [oracle@dg1 standby_bk]$ rman target /
    
    Recovery Manager: Release 11.2.0.4.0 - Production on Wed May 6 16:18:56 2020
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    RMAN> restore standby  controlfile  to '/u01/app/oracle/oradata/cad02/control01.ctl' from '/home/oracle/standby_bk/standby_20200506_09uvhd2k_1_1.bak';    
    
    Starting restore at 06-MAY-20
    using target database control file instead of recovery catalog
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=63 device type=DISK
    
    channel ORA_DISK_1: restoring control file
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    Finished restore at 06-MAY-20
    RMAN> restore standby  controlfile  to '/u01/app/oracle/fast_recovery_area/cad02/control02.ctl' from '/home/oracle/standby_bk/standby_20200506_09uvhd2k_1_1.bak';
    
    Starting restore at 06-MAY-20
    using channel ORA_DISK_1
    
    channel ORA_DISK_1: restoring control file
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    Finished restore at 06-MAY-20
    
    RMAN> alter database mount;
    
    database mounted
    released channel: ORA_DISK_1
    
    RMAN> catalog start with '/home/oracle/standby_bk/';
    
    Starting implicit crosscheck backup at 06-MAY-20
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=131 device type=DISK
    Finished implicit crosscheck backup at 06-MAY-20
    
    Starting implicit crosscheck copy at 06-MAY-20
    using channel ORA_DISK_1
    Crosschecked 2 objects
    Finished implicit crosscheck copy at 06-MAY-20
    
    searching for all files in the recovery area
    cataloging files...
    no files cataloged
    
    searching for all files that match the pattern /home/oracle/standby_bk/
    
    List of Files Unknown to the Database
    =====================================
    File Name: /home/oracle/standby_bk/standby_20200506_07uvhd04_1_1.bak
    File Name: /home/oracle/standby_bk/standby_20200506_08uvhd0c_1_1.bak
    File Name: /home/oracle/standby_bk/standby_20200506_09uvhd2k_1_1.bak
    
    Do you really want to catalog the above files (enter YES or NO)? yes
    cataloging files...
    cataloging done
    
    List of Cataloged Files
    =======================
    File Name: /home/oracle/standby_bk/standby_20200506_07uvhd04_1_1.bak
    File Name: /home/oracle/standby_bk/standby_20200506_08uvhd0c_1_1.bak
    File Name: /home/oracle/standby_bk/standby_20200506_09uvhd2k_1_1.bak
    RMAN> recover database noredo;
    
    Starting recover at 06-MAY-20
    using channel ORA_DISK_1
    
    Finished recover at 06-MAY-20

    备份库

    SQL> col name for a100
    SQL> set linesize 9999  pagesize 9999
    SQL> SELECT dest_id,THREAD#,NAME,sequence#,archived,applied,a.NEXT_CHANGE#
    FROM   v$archived_log a
    WHERE  a.sequence# >= 200
    AND    resetlogs_change# = (SELECT d.RESETLOGS_CHANGE# FROM v$database d)
    and a.dest_id=1
    ORDER  BY a.THREAD#,
    a.sequence#,a.dest_id;  2    3    4    5    6    7  
    
       DEST_ID    THREAD# NAME                                                    SEQUENCE# ARC APPLIED   NEXT_CHANGE#
    ---------- ---------- ---------------------------------------------------------------------------------------------------- ---------- --- --------- ------------
         1        1 /u01/app/oracle/archive/1_623_1032629558.arch                                  623 YES NO        17929963
         1        2 /u01/app/oracle/archive/2_385_1032629558.arch                                  385 YES NO        17929957
    
    SQL> alter database recover managed standby database using current logfile disconnect from session;
    
    Database altered.
    
    SQL> SELECT * FROM V$ARCHIVE_GAP;
    
    no rows selected
    SQL> alter database recover managed standby database cancel;
    
    Database altered.
    
    SQL> alter database open;
    alter database open
    *
    ERROR at line 1:
    ORA-10458: standby database requires recovery
    ORA-01196: file 1 is inconsistent due to a failed media recovery session
    ORA-01110: data file 1: '/u01/app/oracle/oradata/cad02/data/system.271.1032629567'

    ##ERROR log

    Wed May 06 16:41:33 2020
    Managed Standby Recovery starting Real Time Apply
    Parallel Media Recovery started with 4 slaves
    Waiting for all non-current ORLs to be archived...
    All non-current ORLs have been archived.
    Media Recovery Waiting for thread 2 sequence 241
    Fetching gap sequence in thread 2, gap sequence 241-340
    Completed:  alter database recover managed standby database using current logfile disconnect from session
    Wed May 06 16:44:14 2020
    FAL[client]: Failed to request gap sequence
     GAP - thread 2 sequence 241-340
     DBID 1640682678 branch 1032629558
    FAL[client]: All defined FAL servers have been attempted.
    ------------------------------------------------------------
    Check that the CONTROL_FILE_RECORD_KEEP_TIME initialization
    parameter is defined to a value that's sufficiently large
    enough to maintain adequate log switch information to resolve
    archivelog gaps.
    ------------------------------------------------------------

    当查询v$datafile scn,database scn,datafile_header.scn发现均不一致,这个时候不能使用CURRENT_SCN来作为scn增量备份的起点,这个时候需要根据缺少日志最下sequence#找出scn,然后作为增量备份的起点.

    SQL>  select FIRST_CHANGE#  from v$archived_log where SEQUENCE#  =241; ##找不到scn号,归档日志已经被清理
    
    no rows selected

    所以使用gap中提示的sequence#找出起始scn比CURRENT_SCN 更加靠谱(出现scn不一致情况,一般人工不正常干预dg导致

    这里在主备库都查询不到241-244的归档日志信息,而且个人测试环境没有备份,所有后面只能重建adg了。

    文档参考:

    http://www.xifenfei.com/2011/07/data-guard%E5%87%BA%E7%8E%B0gap-sequence%E4%BF%AE%E5%A4%8D.html
    https://www.cnblogs.com/lhrbest/p/4754289.html

  • 相关阅读:
    【转】PowerManager 与 WakeLock
    【转】设计模式总结之模式分类
    【转】一篇文章,教你学会Git
    【转】Iconfont
    【转】码云source tree 提交超过100m 为什么大文件推不上去
    各 Android 平台版本支持的 API 级别
    【转】Android进程机制
    【转】数据库CRUD操作
    【转】数据库--视图的基本概念以及作用
    动态规划的两种形式
  • 原文地址:https://www.cnblogs.com/yhq1314/p/12843648.html
Copyright © 2020-2023  润新知