一:DG之主备切换(主切备、备切主)
1)主切备:
SYS@ORA11GR2>select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SYS@ORA11GR2>alter database commit to switchover to physical standby with session shutdown; (主切备,后台进程关掉了数据库)
ERROR:
ORA-01034: ORACLE not available
Process ID: 17761
Session ID: 106 Serial number: 1421
Database altered.
SYS@ORA11GR2>conn / as sysdba
Connected to an idle instance.
SYS@ORA11GR2>startup mount;
ORACLE instance started.
Total System Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 503319672 bytes
Database Buffers 322961408 bytes
Redo Buffers 2392064 bytes
Database mounted.
SYS@ORA11GR2>select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY RECOVERY NEEDED
——需应用日志:
SYS@ORA11GR2>recover managed standby database using current logfile disconnect from session;
Media recovery complete.
此时转换后的备库一直在应用日志,如果需要再次转换为主库需结束应用日志:
SYS@ORA11GR2>select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
2)备切主:
[oracle@bing ~]$ export ORACLE_SID=OCMU
[oracle@bing ~]$ echo $ORACLE_SID
OCMU
[oracle@bing ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 20 13:25:13 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY NOT ALLOWED (没有主库,状态显示不正常,正常应为to primary)
——切换一下
SQL> alter database commit to switchover to primary with session shutdown;
alter database commit to switchover to primary with session shutdown
*
ERROR at line 1:
ORA-16139: media recovery required
——根据提示,应用日志:
SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.
再次查看状态:
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY(正常了)
(因为有主库,则状态为not allowed;如果没有主库,则状态都为to primary)
——备切主操作:
SQL> alter database commit to switchover to primary with session shutdown;
(备切主后,后台进程直接关库,再将库启动到mount下)
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY NOT ALLOWED (备切主后数据库状态为mount)
——启库:
SQL> alter database open;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY RESOLVABLE GAP
——转换后的备库正在应用日志,过会再看一下转换后的主库状态:
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY TO STANDBY(正常)
——过会再看一下转换后的主库状态:
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE(正常)
二:反切(即将切换后的备库切换回主库,切换后的主库切换回备库)
1).主切备操作:
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered. (主切备,后台进程关掉了数据库)
SQL> select open_mode from v$database;
select open_mode from v$database
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 8010
Session ID: 1 Serial number: 7
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 830930944 bytes
Fixed Size 2257800 bytes
Variable Size 675286136 bytes
Database Buffers 150994944 bytes
Redo Buffers 2392064 bytes
Database mounted.
SQL>
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY RECOVERY NEEDED
SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL> recover managed standby database cancel;
Media recovery complete.
SQL>
2).备切主操作:
SYS@ORA11GR2>select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SYS@ORA11GR2>alter database commit to switchover to primary with session shutdown;
Database altered. (备切主后,后台进程直接关库,再将库启动到mount下)
SYS@ORA11GR2>alter database open;
Database altered.
SYS@ORA11GR2>select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
3).再次查看下切换后的备库状态:
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY RECOVERY NEEDED
SQL> recover managed standby database using current logfile disconnect from session;
Media recovery complete.
SQL>
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY NOT ALLOWED
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY NOT ALLOWED
完成!!!!!!!!!!!!!!!!!!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31397003/viewspace-2126910/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31397003/viewspace-2126910/