swithover一般用于数据库升级或硬件升级,这时只需要较短时间中断数据库访问,主备库的角色切换完成后,即可打开primay角色的备库来提供数据库访问。
主库上面:
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> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1073741824 bytes
Fixed Size 1223540 bytes
Variable Size 864027788 bytes
Database Buffers 205520896 bytes
Redo Buffers 2969600 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
39
备库上面操作:
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY TO PRIMARY
如果swithover_status状态为recovery needed或swithover latent,需要应用完所有归档日志后才能切换(alter database recover managed standby database disconnect from session;)
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> alter database open;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY SESSIONS ACTIVE
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
39
SQL> alter system switch logfile;
进主库:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
40