--目前主库PROD3,备库AUX
--查看主备库日志传输情况
SYS@PROD3> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
34
SYS@aux> select sequence#,applied from v$archived_log order by 1 desc;
SEQUENCE# APPLIED
---------- ---------
34 YES
34 YES
34 YES
33 YES
32 YES
31 YES
30 YES
--查看主备库状态
SYS@PROD3> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROD3 PRIMARY TO STANDBY
SYS@aux> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROD3 PHYSICAL STANDBY NOT ALLOWED
--先主库切换到备库
SYS@PROD3> alter database commit to switchover to physical standby with session shutdown;
Database altered.
--同时备库trace文件中节选
RFS[2]: Possible network disconnect with primary database
SYS@aux> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROD3 PHYSICAL STANDBY TO PRIMARY
--备库切换到主库
SYS@aux> alter database commit to switchover to primary;
Database altered.
SYS@aux> alter database open;
Database altered.
--启动备库进行恢复
SYS@PROD3> startup
ORACLE instance started.
Total System Global Area 958341120 bytes
Fixed Size 1348972 bytes
Variable Size 281021076 bytes
Database Buffers 671088640 bytes
Redo Buffers 4882432 bytes
Database mounted.
Database opened.
SYS@PROD3> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY
SYS@PROD3> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROD3 PHYSICAL STANDBY RECOVERY NEEDED
SYS@PROD3> alter database recover managed standby database disconnect from session;
Database altered.
SYS@PROD3> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROD3 PHYSICAL STANDBY NOT ALLOWED
SYS@PROD3> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
--查看主库状态
SYS@aux> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROD3 PRIMARY TO STANDBY