12C下Dataguar的主备库的切换

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xxzhaobb/article/details/82319558

RDBMS 12.2.0.1. Platform :Windows X64 。

12C的DataGuard的切换,可以仍旧使用11g的方法。也可以使用12c的方法。

本文参考MOS的官方文档:MOS 2403970.1

12c data guard 使用 sqlplus 主备切换最佳实践 (文档 ID 2403970.1)

本次测试,主库是nocdb,对应的db_unique_name是nocdb,备库是nocdb_stdby,对应的db_unique_name是nocdb_stdby. 

主库 nocdb,db_unique_name= nocdb 

SYS@nocdb>col database_role for a20
SYS@nocdb>col db_unique_name for a15
SYS@nocdb>col swithover_status for a24
SYS@nocdb>select database_role,db_unique_name,switchover_status from v$database;

DATABASE_ROLE        DB_UNIQUE_NAME  SWITCHOVER_STATUS
-------------------- --------------- ----------------------------------------
PRIMARY              nocdb           TO STANDBY

SYS@nocdb>

备库 nocdb_stdby, db_unique_name=nocdb_stdby 

SYS@nocdb_stdby>col database_role for a20
SYS@nocdb_stdby>col db_unique_name for a15
SYS@nocdb_stdby>col swithover_status for a24
SYS@nocdb_stdby>select database_role,db_unique_name,switchover_status from v$database;

DATABASE_ROLE        DB_UNIQUE_NAME  SWITCHOVER_STATUS
-------------------- --------------- ----------------------------------------
PHYSICAL STANDBY     nocdb_stdby     NOT ALLOWED

SYS@nocdb_stdby>

切换之前的检查

alter database switchover to nocdb_stdby verify; -- 主库执行
alter database switchover to nocdb verify;    -- 备库执行(提示ORA-016465 ,必须在打开的主数据库上启动操作)

SYS@nocdb>alter database switchover to nocdb_stdby verify;

数据库已更改。

SYS@nocdb>

在主库的alert log中有以下提示

2018-09-02T20:46:16.785697+08:00
alter database switchover to nocdb_stdby verify
2018-09-02T20:46:17.020072+08:00
SWITCHOVER VERIFY: Send VERIFY request to switchover target NOCDB_STDBY
SWITCHOVER VERIFY COMPLETE: READY FOR SWITCHOVER
Completed: alter database switchover to nocdb_stdby verify

在备库的alertlog上有以下提示

2018-09-02T20:45:25.676322+08:00
alter database switchover to nocdb verify
ORA-16465 signalled during: alter database switchover to nocdb verify...
2018-09-02T20:46:17.066947+08:00
SWITCHOVER VERIFY BEGIN
SWITCHOVER VERIFY COMPLETE

-- 如果v$database的switchover_status的值为unresolvable gap

如果 v$database 的 switchover_status 的值为 UNRESOLVABLE GAP(RAC 或者非 RAC)

1. 检查是否有些关闭的线程存在并且 disable

SQL>SELECT thread#, instance, status FROM v$thread;

Disable 线程使用:

SQL> ALTER DATABASE DISABLE THREAD <n>;

2. 检查是否有 log_archive_destination 指向不合法的目录

SQL> select status,DEST_ID,TYPE,ERROR,GAP_STATUS,SYNCHRONIZED,SYNCHRONIZATION_STATUS,RECOVERY_MODE from V$ARCHIVE_DEST_STATUS where STatus <> 'INACTIVE';
SQL>show parameter log_Archive_dest

切换角色
在主库和备库上同时开启trace ,以方便出现问题时候诊断
alter system set log_archive_trace=8191 sid=’*’;

show parameter background_dump_dest
 

alter database switchover to nocdb_stdby; -- 在原主库上执行

SYS@nocdb>alter database switchover to nocdb_stdby;

数据库已更改。

SYS@nocdb>

查看原主库备库的alert log 。随后,原主库shutdown 

2018-09-02T20:57:34.004447+08:00
alter database switchover to nocdb_stdby
2018-09-02T20:57:34.004447+08:00
The Time Management Interface (TMI) is being enabled for role
transition information.  This will result in messages being
output to the alert log file with the prefix 'TMI: '.  This is
being enabled to make the timing of the various stages of the
role transition available for diagnostic purposes.  This
output will end when the role transition is complete.
TMI: dbsdrv switchover to target BEGIN 2018-09-02 20:57:34.004447 
Starting switchover [Process ID: 4824]
TMI: kcv_switchover_to_target convert to physical BEGIN 2018-09-02 20:57:34.254447 
Waiting for target standby to receive all redo
2018-09-02T20:57:34.285697+08:00
Waiting for all non-current ORLs to be archived
2018-09-02T20:57:34.285697+08:00
All non-current ORLs have been archived
2018-09-02T20:57:34.285697+08:00
Waiting for all FAL entries to be archived
2018-09-02T20:57:34.285697+08:00
All FAL entries have been archived
2018-09-02T20:57:34.285697+08:00
Waiting for LAD:2 to become synchronized
2018-09-02T20:57:35.285697+08:00
Active, synchronized Physical Standby switchover target has been identified
Preventing updates and queries at the Primary
2018-09-02T20:57:36.285697+08:00
Generating and shipping final logs to target standby
Switchover End-Of-Redo Log thread 1 sequence 17 has been fixed
Switchover: Primary highest seen SCN set to 0x00000000001c472c
ARCH: Noswitch archival of thread 1, sequence 17
ARCH: End-Of-Redo Branch archival of thread 1 sequence 17
ARCH: LGWR is scheduled to archive to LAD:2 after log switch
ARCH: Standby redo logfile selected for thread 1 sequence 17 for destination LOG_ARCHIVE_DEST_2
2018-09-02T20:57:37.285697+08:00
ARCH: Archiving is disabled due to current logfile archival
Primary will check for some target standby to have received all redo
Waiting for target standby to apply all redo
2018-09-02T20:57:38.348197+08:00
Backup controlfile written to trace file E:\APP\TEST\VIRTUAL\diag\rdbms\nocdb\nocdb\trace\nocdb_ora_4824.trc
Converting the primary database to a new standby database
Clearing standby activation ID 3226269148 (0xc04cf5dc)
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 209715200;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 209715200;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 209715200;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 209715200;
Archivelog for thread 1 sequence 17 required for standby recovery
Switchover: Primary controlfile converted to standby controlfile succesfully.
Switchover: Complete - Database shutdown required
TMI: kcv_switchover_to_target convert to physical END 2018-09-02 20:57:38.410697 
Sending request(convert to primary database) to switchover target NOCDB_STDBY
2018-09-02T20:58:02.379447+08:00
Process (ospid 3112) is suspended due to switchover to physical standby operation.
2018-09-02T20:58:10.066947+08:00
Switchover complete. Database shutdown required
USER (ospid: 4824): terminating the instance
2018-09-02T20:58:36.254447+08:00
Instance terminated by USER, pid = 4824
TMI: dbsdrv switchover to target END 2018-09-02 20:58:36.254447 
Completed: alter database switchover to nocdb_stdby
Shutting down instance (abort) (OS id: 4824)
License high water mark = 5
2018-09-02T20:58:36.316947+08:00
Instance shutdown complete (OS id: 4824)

查看原备库的alert log 

SWITCHOVER: received request 'ALTER DTABASE COMMIT TO SWITCHOVER  TO PRIMARY' from primary database.
Maximum wait for role transition is 15 minutes.
TMI: kcv_commit_to_so_to_primary wait for MRP to finish BEGIN 2018-09-02 20:57:38.457572 
Switchover: Media recovery is still active
Role Change: Canceling MRP - no more redo to apply
2018-09-02T20:57:38.488822+08:00
MRP0: Background Media Recovery cancelled with status 16037
2018-09-02T20:57:38.504447+08:00
Errors in file E:\APP\TEST\VIRTUAL\diag\rdbms\nocdb_stdby\nocdb_stdby\trace\nocdb_stdby_mrp0_3716.trc:
ORA-16037: 鐢ㄦ埛宸茶姹傚彇娑堝彈绠℃仮澶嶆搷浣?
Managed Standby Recovery not using Real Time Apply
Recovery interrupted!
2018-09-02T20:57:38.535697+08:00
Errors in file E:\APP\TEST\VIRTUAL\diag\rdbms\nocdb_stdby\nocdb_stdby\trace\nocdb_stdby_mrp0_3716.trc:
ORA-16037: 鐢ㄦ埛宸茶姹傚彇娑堝彈绠℃仮澶嶆搷浣?
2018-09-02T20:57:39.457572+08:00
Role Change: Canceled MRP
TMI: kcv_commit_to_so_to_primary wait for MRP to finish END 2018-09-02 20:57:39.457572 
TMI: kcv_commit_to_so_to_primary Switchover from physical BEGIN 2018-09-02 20:57:39.457572 
Killing 2 processes (PIDS:4784,1032) (all RFS) in order to disallow current and future RFS connections. Requested by OS process 5880
2018-09-02T20:57:46.395072+08:00
Stopping Emon pool
Dispatchers and shared servers shutdown
CLOSE: killing server sessions.
2018-09-02T20:58:09.254447+08:00
CLOSE: all sessions shutdown successfully.
Stopping Emon pool
Backup controlfile written to trace file E:\APP\TEST\VIRTUAL\diag\rdbms\nocdb_stdby\nocdb_stdby\trace\nocdb_stdby_rmi_5880.trc
SwitchOver after complete recovery through change 1853228
Online logfile pre-clearing operation disabled by switchover
Online log E:\ORADATA\NOCDB_STDBY\REDO01.LOG: Thread 1 Group 1 was previously cleared
Online log E:\ORADATA\NOCDB_STDBY\REDO02.LOG: Thread 1 Group 2 was previously cleared
Online log E:\ORADATA\NOCDB_STDBY\REDO03.LOG: Thread 1 Group 3 was previously cleared
Standby became primary SCN: 1853226
The Time Management Interface (TMI) is being enabled for role
transition information.  This will result in messages being
output to the alert log file with the prefix 'TMI: '.  This is
being enabled to make the timing of the various stages of the
role transition available for diagnostic purposes.  This
output will end when the role transition is complete.
Network throttle feature is disabled as mount time

AUDIT_TRAIL initialization parameter is changed back to its original value as specified in the parameter file.
Switchover: Complete - Database mounted as primary
TMI: kcv_commit_to_so_to_primary Switchover from physical END 2018-09-02 20:58:10.066947 
SWITCHOVER: completed request from primary database.
2018-09-02T20:58:27.566947+08:00
ARC0: Becoming the 'no SRL' ARCH

注意:备库一端只等待15分钟,实现备库与主库的同步

Maximum wait for role transition is 15 minutes. 这行

-- 打开新的主库 (此时,原主库关闭,原备库是mount状态)。
-- 打开新的备库,并启用日志应用

-- 查看新的主库状态

SYS@nocdb_stdby>select open_mode from v$database;

OPEN_MODE
----------------------------------------
MOUNTED

SYS@nocdb_stdby>alter database open;

数据库已更改。

SYS@nocdb_stdby>select database_role,db_unique_name,switchover_status from v$database;

DATABASE_ROLE        DB_UNIQUE_NAME  SWITCHOVER_STATUS
-------------------- --------------- ----------------------------------------
PRIMARY              nocdb_stdby     TO STANDBY

SYS@nocdb_stdby>

-- 查看新的备库状态

SYS@nocdb>conn / as sysdba
已连接到空闲例程。
SYS@nocdb>startup
ORACLE 例程已经启动。

Total System Global Area 1073741824 bytes
Fixed Size                  8755392 bytes
Variable Size             729810752 bytes
Database Buffers          331350016 bytes
Redo Buffers                3825664 bytes
数据库装载完毕。
数据库已经打开。
SYS@nocdb>alter database recover managed standby database using current logfile disconnect from session;

数据库已更改。

SYS@nocdb>select database_role,db_unique_name,switchover_status from v$database;

DATABASE_ROLE        DB_UNIQUE_NAME  SWITCHOVER_STATUS
-------------------- --------------- ----------------------------------------
PHYSICAL STANDBY     nocdb           NOT ALLOWED

SYS@nocdb>

end

越来越简单了 ,以后dba要失业了 。 

猜你喜欢

转载自blog.csdn.net/xxzhaobb/article/details/82319558