当DG进行failover之后重新恢复DG(利用rman 11gduplicate的ADG特性)

1 主库设置为 force loging 模式

 

5:48:54 sys@felix SQL>alter database force logging;

 

-- 验证 :

16:10:00 sys@felix SQL>selectforce_logging from v$database;

 

FORCE_

------

YES

 

查看主备库监听配置问题:

 

[oracle@felix ~]$ tnsping felix_st

 

TNS Ping Utility for Linux: Version11.2.0.3.0 - Production on 26-MAR-2014 16:12:49

 

Copyright (c) 1997, 2011, Oracle.  All rights reserved.

 

Used parameter files:

 

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.10.14)(PORT = 1521))) (CONNECT_DATA =(SERVICE_NAME = felix_st)))

OK (110 msec)

 

 

******************************************************************************************************************************************

 

[oracle@standby ~]$ tnsping felix_pd

 

TNS Ping Utility for Linux: Version11.2.0.3.0 - Production on 26-MAR-2014 16:12:37

 

Copyright (c) 1997, 2011, Oracle.  All rights reserved.

 

Used parameter files:

 

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.10.13)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME= felix_pd)))

OK (50 msec)

 

spfile将备库处于nomount状态下:

 

 

开始进行duplicate

 

这个操作主备库都可以,只要RMAN连接时没有写错就行了。

 

rman targetsys/oracle@felix_st auxiliary sys/oracle@felix_pd

 

duplicate target database for standby fromactive database;

 

如果路径相同,使用这个:

duplicate target database for standby fromactive database nofilenamecheck;

 

 

 

以下是输出日志:

 

RMAN> duplicate target database for standby fromactive database nofilenamecheck;

 

(注意观察日志内容)

Starting Duplicate Db at 26-MAR-14

using target database control file insteadof recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=21 devicetype=DISK

 

contents of Memory Script:

{

   backup as copy reuse

   targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwfelix' auxiliary format

 '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwfelix'   ;

}

----这个是目录格式转换

 

executing Memory Script

 

Starting backup at 26-MAR-14

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=44 device type=DISK

Finished backup at 26-MAR-14

 

contents of Memory Script:

{

   backup as copy current controlfile for standbyauxiliary format '/u01/app/oracle/oradata/felix/control01.ctl';

   restore clone controlfile to  '/u01/app/oracle/fast_recovery_area/felix/control02.ctl'from

 '/u01/app/oracle/oradata/felix/control01.ctl';

 

}

executing Memory Script

 

Starting backup at 26-MAR-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

copying standby control file

output filename=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_felix.ftag=TAG20140326T162408 RECID=2 STAMP=843236650

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:07

Finished backup at 26-MAR-14

 

Starting restore at 26-MAR-14

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: copied control filecopy

Finished restore at 26-MAR-14

 

contents of Memory Script:

{

   sql clone 'alter database mount standby database';

}

executing Memory Script

 

sql statement: alter database mount standbydatabase

 

contents of Memory Script:

{

   set newname for tempfile  1 to

 "/u01/app/oracle/oradata/felix/temp01.dbf";

   switch clone tempfile all;

   set newname for datafile  1 to

 "/u01/app/oracle/oradata/felix/system01.dbf";

   set newname for datafile  2 to

 "/u01/app/oracle/oradata/felix/sysaux01.dbf";

   set newname for datafile  3 to

 "/u01/app/oracle/oradata/felix/undotbs01.dbf";

   set newname for datafile  4 to

 "/u01/app/oracle/oradata/felix/users01.dbf";

   set newname for datafile  5 to

 "/u01/app/oracle/oradata/felix/example01.dbf";

   backup as copy reuse

   datafile  1 auxiliary format

 "/u01/app/oracle/oradata/felix/system01.dbf"   datafile

 2 auxiliary format

 "/u01/app/oracle/oradata/felix/sysaux01.dbf"   datafile

 3 auxiliary format

 "/u01/app/oracle/oradata/felix/undotbs01.dbf"   datafile

 4 auxiliary format

 "/u01/app/oracle/oradata/felix/users01.dbf"   datafile

 5 auxiliary format

 "/u01/app/oracle/oradata/felix/example01.dbf"   ;

   sql 'alter system archive logcurrent';

}

executing Memory Script

 

executing command: SET NEWNAME

 

renamed tempfile 1 to/u01/app/oracle/oradata/felix/temp01.dbf in control file

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

Starting backup at 26-MAR-14

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001name=/u01/app/oracle/oradata/felix/system01.dbf

output filename=/u01/app/oracle/oradata/felix/system01.dbf tag=TAG20140326T162424

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:02:05

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002name=/u01/app/oracle/oradata/felix/sysaux01.dbf

output filename=/u01/app/oracle/oradata/felix/sysaux01.dbf tag=TAG20140326T162424

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:01:36

channel ORA_DISK_1: starting datafile copy

input datafile file number=00005name=/u01/app/oracle/oradata/felix/example01.dbf

output filename=/u01/app/oracle/oradata/felix/example01.dbf tag=TAG20140326T162424

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:01:06

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003name=/u01/app/oracle/oradata/felix/undotbs01.dbf

output filename=/u01/app/oracle/oradata/felix/undotbs01.dbf tag=TAG20140326T162424

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:25

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004name=/u01/app/oracle/oradata/felix/users01.dbf

output filename=/u01/app/oracle/oradata/felix/users01.dbf tag=TAG20140326T162424

channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:15

Finished backup at 26-MAR-14

 

sql statement: alter system archive logcurrent

 

contents of Memory Script:

{

  switch clone datafile all;

}

executing Memory Script

 

datafile 1 switched to datafile copy

input datafile copy RECID=2 STAMP=843236998file name=/u01/app/oracle/oradata/felix/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=3 STAMP=843236998file name=/u01/app/oracle/oradata/felix/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=4 STAMP=843236998file name=/u01/app/oracle/oradata/felix/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=5 STAMP=843236998file name=/u01/app/oracle/oradata/felix/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=6 STAMP=843236998file name=/u01/app/oracle/oradata/felix/example01.dbf

Finished Duplicate Db at 26-MAR-14

 

 

打开备库:

16:35:27 sys@felix SQL>alter databaseopen;

 

Database altered.

 

16:35:45 sys@felix SQL>select statusfrom v$instance;

 

STATUS

------------------------

OPEN

 

16:36:32 sys@felix SQL>select open_modefrom v$database;

 

OPEN_MODE

----------------------------------------

READ ONLY

 

 

查看主库:

16:35:56 sys@felix SQL>select statusfrom v$instance;

 

STATUS

------------------------

OPEN

 

16:36:13 sys@felix SQL>select open_modefrom v$database;

 

OPEN_MODE

----------------------------------------

READ WRITE

 

验证数据库:

启动实时应用:

16:40:18 sys@felix SQL>alter databaserecover managed standby database using current logfile disconnect from session;

 

Database altered.

 

desc v$managed_standby; 

 Name                                Null?        Type

 -----------------------------------------------------------------------------

 PROCESS                            VARCHAR2(9)

 PID                                NUMBER

 STATUS                             VARCHAR2(12)

 CLIENT_PROCESS                     VARCHAR2(8)

 CLIENT_PID                         VARCHAR2(40)

 CLIENT_DBID                        VARCHAR2(40)

 GROUP#                             VARCHAR2(40)

 RESETLOG_ID                        NUMBER

 THREAD#                            NUMBER

 SEQUENCE#                          NUMBER

 BLOCK#                             NUMBER

 BLOCKS                             NUMBER

 DELAY_MINS                         NUMBER

 KNOWN_AGENTS                       NUMBER

 ACTIVE_AGENTS                      NUMBER

 

 

sys@felix SQL>selectprocess,thread#,status from v$managed_standby;

 

PROCESS               THREAD# STATUS

------------------ ----------------------------------

ARCH                        1 CLOSING

ARCH                       1 CLOSING

ARCH                        0 CONNECTED

ARCH                        1 CLOSING

RFS                         0 IDLE

RFS                         0 IDLE

RFS                         0 IDLE

RFS                         1 IDLE

MRP0                       1 APPLYING_LOG

 

实时应用已经成功运行;

 

然后再主库进行日志切换:

 

16:54:57 sys@felix SQL>alter systemswitch logfile;

 

System altered.

 

16:55:15 sys@felix SQL>alter systemswitch logfile;

 

System altered.

 

查看主库日志最大序列:

SQL>select max(sequence#) from v$log;

 

MAX(SEQUENCE#)

--------------

           14

再查看备库的最大序列:

SQL>select max(sequence#) from v$log;

 

MAX(SEQUENCE#)

--------------

           14

说明已经同步成功

 

 

 

现在开始进行主备库切换:(切换到原来的主库)

启动备库到mount状态:

17:02:11 SQL>startup  mount;

ORACLE instance started.

 

Total System Global Area  417546240 bytes

Fixed Size                  2228944 bytes

Variable Size             322964784 bytes

Database Buffers           88080384 bytes

Redo Buffers                4272128 bytes

Database mounted.

17:02:33 SQL>select status from v$instance;

 

STATUS

------------------------

MOUNTED

 

17:03:03 SQL>

 

 

主库再open状态:

 

16:55:20 sys@felix SQL>select statusfrom v$instance;

 

STATUS

------------------------

OPEN

 

 

查看主库的switchover状态:

 

7:03:09 sys@felix SQL>selectswitchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

TO STANDBY

 

执行切换命令:

17:05:14 sys@felix SQL>alter databasecommit to switchover to physical standby;

alter database commit to switchover tophysical standby

*

ERROR at line 1:

ORA-01093: ALTER DATABASE CLOSE onlypermitted with no sessions connected

 

 

17:07:36 sys@felix SQL>alter databasecommit to switchover to physical standby with session shutdown;

 

Database altered.

 

 

备库执行切换命令:

17:03:03 SQL>alter database commit to switchover to primary;

alter database commit to switchover toprimary

*

ERROR at line 1:

ORA-16139: media recovery required

 

启动mrp实时应用,进行media恢复;

 

 

17:15:02 SQL>alter database recover managed standby database using currentlogfile disconnect from session;

 

Database altered.

 

17:17:04 SQL>select switchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

TO PRIMARY

 

17:17:40 SQL>alter database commit to switchover to primary;

 

Database altered.

 

 

验证:

(1)主库执行

17:20:51 SQL>select name,DATABASE_ROLE,DB_UNIQUE_NAME  from v$database;

 

NAME                           DATABASE_ROLE                    DB_UNIQUE_NAME

-------------------------------------------------------------- ------------------------------------------------------------

FELIX                          PRIMARY                          felix_pd

(2)备库执行

17:14:34 SQL>select name,DATABASE_ROLE,DB_UNIQUE_NAME  from v$database;

 

NAME                           DATABASE_ROLE                    DB_UNIQUE_NAME

--------------------------------------------------------------------------------------------------------------------------

FELIX                          PHYSICAL STANDBY                 felix_st

 

 

然后打开主备库:

alter database open;

 

进行日志切换:

alter system switch logile;

 

查看日志是否同步:

 

(主库)17:22:42  SQL>selectmax(sequence#) from v$log;

 

MAX(SEQUENCE#)

--------------

           20

(备库)17:23:18  SQL>selectmax(sequence#) from v$log;

 

MAX(SEQUENCE#)

--------------

           20

 

 

OK,到此全部执行完成!!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Oracle,系列,data,guard,database,oracle,switch,rman)