作者:广大
注意:原则上至多只能有一个主库,但是备库可以多个,所以需要先进行主库转备库操作。
SYS@proe>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
------------------------- ---------------- --------------------
PROE PRIMARY TO STANDBY
SYS@proe>alter database commit to switchover to physical standby;
Database altered.
SYS@proe>shutdown abort
ORACLE instance shut down.
SYS@proe>startup mount;
ORACLE instance started.
# 查看此时角色切换状态
SYS@proe>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
------------------------- ---------------- --------------------
PROE PHYSICAL STANDBY RECOVERY NEEDED
# 查看角色保护模式和级别
SYS@proe> select name,database_role,protection_mode,protection_level from v$database;
NAME DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
------------------------- ---------------- -------------------- --------------------
PROE PHYSICAL STANDBY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
"TO STANDBY"意味着主库此时可以切换为备库,如果状态为SESSION ACTIVE可以使用以下命令切换。然后执行上述切换后的操作。
SYS@proe>alter database commit to switchover to physical standby with session shutdown;
SYS@stddb>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROE PHYSICAL STANDBY TO PRIMARY
SYS@stddb>alter database commit to switchover to primary;
Database altered.
# 查看此时角色切换状态
SYS@stddb>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROE PRIMARY NOT ALLOWED
# 查看角色保护模式和级别
SYS@stddb>select name,database_role,protection_mode,protection_level from v$database;
NAME DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
--------- ---------------- -------------------- --------------------
PROE PRIMARY MAXIMUM PERFORMANCE UNPROTECTED
# 备库切换为主库后实例状态
SYS@stddb>select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
stddb MOUNTED
# 将数据库启动到open
SYS@stddb>alter database open;
Database altered.
# 再次查看转换后的角色保护模式及级别,可以看到和原来的主库一致。
SYS@stddb>select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
原来的主库已经切换为备库,查看此时数据库打开模式
SYS@proe>select name,open_mode from v$database;
NAME OPEN_MODE
------------------------- --------------------
PROE MOUNTED
数据库启动到open
SYS@proe>alter database open;
Database altered.
启动数据库的日志应用服务
SYS@proe>alter database recover managed standby database using current logfile disconnect;
Database altered.
# 查看数据库打开模式
SYS@proe>select name,open_mode from v$database;
NAME OPEN_MODE
------------------------- --------------------
PROE READ ONLY WITH APPLY
一次完整的主备切换完成
更多技术信息请查看云掣官网https://yunche.pro/?t=yrgw