Oracle 11g中通过增量备份来解决standby 和primary之间的 lag

来源:互联网 发布:jquery json对象数组 编辑:程序博客网 时间:2024/06/05 04:44

在Oracle 11g中,对于Dataguard,如果standby和primary之间的lag很大,或者primary的redo log丢失,无法应用到standby,可以通过在拷贝增量备份到standby来解决问题。

 步骤如下:以下来自Oracle 官方文档:

11.10.1 Steps for Using RMAN Incremental Backups

Except where stated otherwise, the following steps apply to all three situations just listed.

  1. Stop Redo Apply on the standby database:

    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
  2. On the standby database, compute the FROM SCN for the incremental backup. This is done differently depending on the situation:

    • On a standby that lags far behind the primary database, query the V$DATABASE view and record the current SCN of the standby database:

      SQL> SELECT CURRENT_SCN FROM V$DATABASE;CURRENT_SCN-----------     233995
    • On a standby that has widespread nologging changes, query the V$DATAFILE view to record the lowest FIRST_NONLOGGED_SCN:

      SQL> SELECT MIN(FIRST_NONLOGGED_SCN) FROM V$DATAFILE -> WHERE FIRST_NONLOGGED_SCN>0;MIN(FIRST_NONLOGGED_SCN)------------------------                  223948
    • On a standby that has nologging changes on a subset of datafiles, query the V$DATAFILE view, as follows:

      SQL> SELECT FILE#, FIRST_NONLOGGED_SCN FROM V$DATAFILE -> WHERE FIRST_NONLOGGED_SCN > 0;FILE#      FIRST_NONLOGGED_SCN---------- -------------------         4              225979         5              230184
  3. Connect to the primary database as the RMAN target and create an incremental backup from the current SCN (for a standby lagging far behind the primary) or from the lowest FIRST_NONLOGGED_SCN (for a standby with widespread nologging changes) of the standby database that was recorded in step2:

    RMAN> BACKUP INCREMENTAL FROM SCN 233995 DATABASE FORMAT '/tmp/ForStandby_%U' tag 'FORSTANDBY';

    If the standby has nologging changes on a subset of datafiles, then create an incremental backup for each datafile listed in the FIRST_NONLOGGED_SCNcolumn (recorded in step 2), as follows:

    RMAN> BACKUP INCREMENTAL FROM SCN 225979 DATAFILE 4 FORMAT '/tmp/ForStandby_%U' TAG 'FORSTANDBY';RMAN> BACKUP INCREMENTAL FROM SCN 230184 DATAFILE 5 FORMAT '/tmp/ForStandby_%U' TAG 'FORSTANDBY';

    The BACKUP commands shown generate datafile backups, as well as a control file backup that will be used in step 7.

  4. If the backup pieces are not on shared storage, then transfer all the backup pieces created on the primary to the standby:

    scp /tmp/ForStandby_* standby:/tmp
  5. If you had to copy the backup pieces in the previous step, or if you are not connected to the recovery catalog for the entire process, then you must catalog the new backup pieces on the standby (otherwise, go on to the next step):

    RMAN> CATALOG START WITH '/tmp/ForStandby';
  6. Connect to the standby database as the RMAN target and execute the REPORT SCHEMA statement to ensure that the standby database site is automatically registered and that the files names at the standby site are displayed:

    RMAN> REPORT SCHEMA;
  7. Connect to the standby database as the RMAN target and apply incremental backups by executing the following commands. Note that the RESTORE STANDBY CONTROLFILE FROM TAG command only works if you are connected to the recovery catalog for the entire process. Otherwise, you must use theRESTORE STANDBY CONTROLFILE FROM '<control file backup filename>' command.

    RMAN> STARTUP FORCE NOMOUNT;RMAN> RESTORE STANDBY CONTROLFILE FROM TAG 'FORSTANDBY';RMAN> ALTER DATABASE MOUNT;RMAN> RECOVER DATABASE NOREDO;

    Note:

    If a recovery catalog is used, then the RMAN RECOVER command will fix the path names for datafiles in the standby control file. If no recovery catalog is used, then you must manually edit the file names in your standby control file or use the RMAN SET NEWNAME command to assign the datafile names. See Oracle Database Backup and Recovery Reference for more information about the RMAN RECOVER and SET NEWNAME commands.
  8. On standbys that have widespread nologging changes or that have nologging changes on a subset of datafiles, query the V$DATAFILE view to verify there are no datafiles with nologged changes. The following query should return zero rows:

    SQL> SELECT FILE#, FIRST_NONLOGGED_SCN FROM V$DATAFILE -> WHERE FIRST_NONLOGGED_SCN > 0;

    Note:

    The incremental backup will become obsolete in 7 days, or you can remove it now using the RMAN DELETE command.
  9. Start Redo Apply on the physical standby database:

    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE -> USING CURRENT LOGFILE DISCONNECT FROM SESSION;

0 0