前言:
在日常项目中,出于各种原因,可能需要临时将standby database置为read write模式,需求完成后再恢复正常DataGuard结构。本文经过在10g,11g上DG的验证,梳理了3个比较容易实现的方式。
1. 使用activate stanby database,并利用手动guarantee restore point 还原,适用于 10g&11g
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> create restore point before_test guarantee flashback database;
Restore point created.
SQL> alter database activate standby database;
Database altered.
SQL> select database_role,open_mode,protection_mode,protection_level from v$database;
DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- -------------------- --------------------
PRIMARY MOUNTED MAXIMUM AVAILABILITY UNPROTECTED
SQL> alter database open;
Database altered.
SQL> select database_role,open_mode,protection_mode,protection_level from v$database; --- standby DB is in read write mode now
DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- -------------------- --------------------
PRIMARY READ WRITE MAXIMUM AVAILABILITY RESYNCHRONIZATION
alter database activate standby database
ALTER DATABASE ACTIVATE [PHYSICAL] STANDBY DATABASE (test3)
krsv_proc_kill: Killing 3 processes (all RFS)
Begin: Standby Redo Logfile archival
End: Standby Redo Logfile archival
RESETLOGS after incomplete recovery UNTIL CHANGE 3097888
Archived Log entry 77 added for thread 1 sequence 62 ID 0x37014efb dest 1:
Resetting resetlogs activation ID 922832635 (0x37014efb)
Online log /u02/test3/redo01a.log: Thread 1 Group 1 was previously cleared
Online log /u03/test3/redo01b.log: Thread 1 Group 1 was previously cleared
Online log /u02/test3/redo02a.log: Thread 1 Group 2 was previously cleared
Online log /u03/test3/redo02b.log: Thread 1 Group 2 was previously cleared
Online log /u02/test3/redo03a.log: Thread 1 Group 3 was previously cleared
Online log /u03/test3/redo03b.log: Thread 1 Group 3 was previously cleared
Standby became primary SCN: 3097886
Tue Jan 28 12:39:05 2014
Setting recovery target incarnation to 7 ------------ incarnation plus 1
ACTIVATE STANDBY: Complete - Database mounted as primary
Completed: alter database activate standby database
alter database open
Tue Jan 28 12:41:14 2014
Assigning activation ID 960825149 (0x3945073d)
LGWR: Primary database is in MAXIMUM AVAILABILITY mode
Destination LOG_ARCHIVE_DEST_2 is UNSYNCHRONIZED
LGWR: Destination LOG_ARCHIVE_DEST_1 is not serviced by LGWR
Thread 1 advanced to log sequence 2 (thread open)
Tue Jan 28 12:41:14 2014
ARC0: Becoming the 'no SRL' ARCH
Thread 1 opened at log sequence 2
Current log# 2 seq# 2 mem# 0: /u02/test3/redo02a.log
Current log# 2 seq# 2 mem# 1: /u03/test3/redo02b.log
Successful open of redo thread 1
Tue Jan 28 12:41:14 2014
ARC1: Becoming the 'no SRL' ARCH
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Tue Jan 28 12:41:14 2014
SMON: enabling cache recovery
Archived Log entry 78 added for thread 1 sequence 1 ID 0x3945073d dest 1:
Tue Jan 28 12:41:15 2014
PING[ARC2]: Heartbeat failed to connect to standby 'test3_A'. Error is 16009.
[2926] Successfully onlined Undo Tablespace 1.
Undo initialization finished serial:0 start:76794 end:77134 diff:340 (3 seconds)
Dictionary check beginning
Dictionary check complete
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Database Characterset is AL32UTF8
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Tue Jan 28 12:41:18 2014
QMNC started with pid=25, OS id=2950
LOGSTDBY: Validating controlfile with logical metadata
LOGSTDBY: Validation complete
Completed: alter database open
SQL> alter database convert to physical standby;
alter database convert to physical standby
*
ERROR at line 1:
ORA-01126: database must be mounted in this instance and not open in any instance
SQ L> startup mount force
ORACLE instance started.
Total System Global Area 622149632 bytes
Fixed Size 2230912 bytes
Variable Size 184550784 bytes
Database Buffers 432013312 bytes
Redo Buffers 3354624 bytes
Database mounted.
SQL> flashback database to restore point before_test;
Flashback complete.
SQL> alter database convert to physical standby;
Database altered.
SQL> select status from v$instance;
STATUS
------------
STARTED
SQL> startup force
ORACLE instance started.
Total System Global Area 622149632 bytes
Fixed Size 2230912 bytes
Variable Size 184550784 bytes
Database Buffers 432013312 bytes
Redo Buffers 3354624 bytes
Database mounted.
Database opened.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
2. 使用convert to snapshot standby,还原点会自动进行创建与删除。仅适用11g
SQL> ALTER DATABASE CONVERT TO SNAPSHOT STANDBY;
alter database convert to snapshot standby
Created guaranteed restore point SNAPSHOT_STANDBY_REQUIRED_01/27/2014 21:05:29
krsv_proc_kill: Killing 3 processes (all RFS)
All dispatchers and shared servers shutdown
CLOSE: killing server sessions.
CLOSE: all sessions shutdown successfully.
Mon Jan 27 21:05:30 2014
SMON: disabling cache recovery
Begin: Standby Redo Logfile archival
End: Standby Redo Logfile archival
RESETLOGS after complete recovery through change 3167297
Resetting resetlogs activation ID 922832635 (0x37014efb)
Online log /u02/test3/redo01a.log: Thread 1 Group 1 was previously cleared
Online log /u03/test3/redo01b.log: Thread 1 Group 1 was previously cleared
Online log /u02/test3/redo02a.log: Thread 1 Group 2 was previously cleared
Online log /u03/test3/redo02b.log: Thread 1 Group 2 was previously cleared
Online log /u02/test3/redo03a.log: Thread 1 Group 3 was previously cleared
Online log /u03/test3/redo03b.log: Thread 1 Group 3 was previously cleared
Standby became primary SCN: 3167295
Mon Jan 27 21:05:30 2014
Setting recovery target incarnation to 8
CONVERT TO SNAPSHOT STANDBY: Complete - Database mounted as snapshot standby
Completed: alter database convert to snapshot standby
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
SNAPSHOT STANDBY MOUNTED
SQL> alter database open;
Database altered.
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
SNAPSHOT STANDBY READ WRITE
SQL> startup mount force
ORACLE instance started.
Total System Global Area 622149632 bytes
Fixed Size 2230912 bytes
Variable Size 184550784 bytes
Database Buffers 432013312 bytes
Redo Buffers 3354624 bytes
Database mounted.
SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
Database altered.
ALTER DATABASE CONVERT TO PHYSICAL STANDBY
ALTER DATABASE CONVERT TO PHYSICAL STANDBY (test3)
Flashback Restore Start
Flashback Restore Complete
Drop guaranteed restore point
Guaranteed restore point dropped
Clearing standby activation ID 960771251 (0x394434b3)
The primary database controlfile was created using the
'MAXLOGFILES 16' clause.
There is space for up to 13 standby redo logfiles
Use the following SQL commands on the standby database to create
standby redo logfiles that match the primary database:
ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;
Shutting down archive processes
Archiving is disabled
Mon Jan 27 21:26:20 2014
ARCH shutting down
ARC2: Archival stopped
Mon Jan 27 21:26:20 2014
ARCH shutting down
ARC1: Archival stopped
Mon Jan 27 21:26:20 2014
ARCH shutting down
ARC0: Archival stopped
Mon Jan 27 21:26:20 2014
ARCH shutting down
ARC3: Archival stopped
Completed: ALTER DATABASE CONVERT TO PHYSICAL STANDBY
SQL> startup force
ORACLE instance started.
Total System Global Area 622149632 bytes
Fixed Size 2230912 bytes
Variable Size 184550784 bytes
Database Buffers 432013312 bytes
Redo Buffers 3354624 bytes
Database mounted.
Database opened.
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
alter database recover managed standby database using current logfile disconnect from session
Attempt to start background Managed Standby Recovery process (test3)
Mon Jan 27 21:28:44 2014
MRP0 started with pid=26, OS id=27157
MRP0: Background Managed Standby Recovery process started (test3)
Serial Media Recovery started
Managed Standby Recovery starting Real Time Apply
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Clearing online redo logfile 1 /u02/test3/redo01a.log
Clearing online log 1 of thread 1 sequence number 1
Completed: alter database recover managed standby database using current logfile disconnect from session
Mon Jan 27 21:28:55 2014
Clearing online redo logfile 1 complete
Clearing online redo logfile 2 /u02/test3/redo02a.log
Clearing online log 2 of thread 1 sequence number 2
Clearing online redo logfile 2 complete
Media Recovery Log /u01/archivelogs/test3/1_81_800115694.dbf
Media Recovery Log /u01/archivelogs/test3/1_82_800115694.dbf
Media Recovery Log /u01/archivelogs/test3/1_83_800115694.dbf
Recovery of Online Redo Log: Thread 1 Group 5 Seq 84 Reading mem 0
Mem# 0: /u02/test3/standby_redo05a.log
Mem# 1: /u03/test3/standby_redo05b.log
3. 使用failover将standby置为primary,并利用guarantee restore point 还原 ,适用于10g&11g
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> create restore point before_test guarantee flashback database;
Restore point created.
standby 端:
alter database recover managed standby database finish force;
(force表示立刻停止RFS进程,且此时standby的switchover_status才是to primary。否则是not allowed,如果尝试切换角色会提示ORA-16139: media recovery required)
alter database commit to switchover to physical primary;alter database open;
alter database commit to switchover to primary
ALTER DATABASE SWITCHOVER TO PRIMARY (test3)
Maximum wait for role transition is 15 minutes.
Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/test3_b/test3/trace/test3_ora_27147.trc
Standby terminal recovery start SCN: 3170407
RESETLOGS after complete recovery through change 3170409
Online log /u02/test3/redo01a.log: Thread 1 Group 1 was previously cleared
Online log /u03/test3/redo01b.log: Thread 1 Group 1 was previously cleared
Online log /u02/test3/redo02a.log: Thread 1 Group 2 was previously cleared
Online log /u03/test3/redo02b.log: Thread 1 Group 2 was previously cleared
Online log /u02/test3/redo03a.log: Thread 1 Group 3 was previously cleared
Online log /u03/test3/redo03b.log: Thread 1 Group 3 was previously cleared
Standby became primary SCN: 3170406
Mon Jan 27 21:44:14 2014
Setting recovery target incarnation to 9
Switchover: Complete - Database mounted as primary
Completed: alter database commit to switchover to primary
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PRIMARY MOUNTED
SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
Database altered.
SQL> startup force
ORACLE instance started.
Total System Global Area 622149632 bytes
Fixed Size 2230912 bytes
Variable Size 184550784 bytesDatabase Buffers 432013312 bytes
Redo Buffers 3354624 bytes
Database mounted.
Database opened.
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select process,pid,status,client_process,sequence# from v$managed_standby;
PROCESS PID STATUS CLIENT_P SEQUENCE#
--------- ---------- ------------ -------- ----------
ARCH 29865 CLOSING ARCH 37
ARCH 29867 CLOSING ARCH 38
MRP0 29876 APPLYING_LOG N/A 39
RFS 29882 IDLE UNKNOWN 0
RFS 29884 IDLE LGWR 39