1. 物理standby执行switchover
1) 确认pirmary是否可以切换为standby
PRIMARY>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
2) 切换primary为standby
PRIMARY>alter database commit to switchover to physical standby;
3) 启动原primary到mount状态
此时原primary就是以standby身份在运行了。
4) 确认standby是否可以切换为primary
STANDBY>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
5) 切换standby为primary
STANDBY>alter database commit to switchover to primary;
Database altered.
STANDBY>alter database open;
Database altered.
6) 验证
PRIMARY>select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY
STANDBY>select database_role from v$database;
DATABASE_ROLE
----------------
PRIMARY
可以看到原来的primary现在变成standby,原来的standby变成primary了。
检查新的primary的log_archive_dest参数的设置是否正确:
STANDBY>show parameter log_archive_dest_2
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string service=O01DMS0 ARCH VALID_FOR
=(ONLINE_LOGFILES,PRIMARY_ROLE
) DB_UNIQUE_NAME=O01DMS0
STANDBY>show parameter log_archive_dest_state_2
NAME TYPE VALUE
------------------------------------ ----------- ---------------------
log_archive_dest_state_2 string ENABLE
在新primary端做log switch:
STANDBY>alter system switch logfile;
System altered.
STANDBY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
479
在新standby端查看:
PRIMARY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
479
两边的归档日志的最大序号吻合,说明switchover成功。
2. 物理standby执行failover
1). 检查standby归档文件是否连续
STANDBY>SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
no rows selected
这一步很重要,必须确保所有已生成的归档文件都已传到standby服务器。
如果上述语句有返回结果,则必须把缺失的归档文件从primary端复制到standby端,然后通过以下命令将其加入数据库:
STANDBY>alter database register physical logfile ' filespec'
2). 检查standby归档文件是否完整
STANDBY>SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY threa
d#) AS LAST from V$ARCHIVED_LOG;
THREAD LAST
---------- ----------
1 479
通过上述语句可以查出standby目前序号最大的归档日志为479,如果在primary端有比479更大的归档日志,把它们拷贝过来,然后通过以下命令将其加入数据库:
STANDBY>alter database register physical logfile ' filespec'
3)启动failover
1) 确认pirmary是否可以切换为standby
PRIMARY>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
2) 切换primary为standby
PRIMARY>alter database commit to switchover to physical standby;
3) 启动原primary到mount状态
此时原primary就是以standby身份在运行了。
4) 确认standby是否可以切换为primary
STANDBY>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
5) 切换standby为primary
STANDBY>alter database commit to switchover to primary;
Database altered.
STANDBY>alter database open;
Database altered.
6) 验证
PRIMARY>select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY
STANDBY>select database_role from v$database;
DATABASE_ROLE
----------------
PRIMARY
可以看到原来的primary现在变成standby,原来的standby变成primary了。
检查新的primary的log_archive_dest参数的设置是否正确:
STANDBY>show parameter log_archive_dest_2
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string service=O01DMS0 ARCH VALID_FOR
=(ONLINE_LOGFILES,PRIMARY_ROLE
) DB_UNIQUE_NAME=O01DMS0
STANDBY>show parameter log_archive_dest_state_2
NAME TYPE VALUE
------------------------------------ ----------- ---------------------
log_archive_dest_state_2 string ENABLE
在新primary端做log switch:
STANDBY>alter system switch logfile;
System altered.
STANDBY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
479
在新standby端查看:
PRIMARY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
479
两边的归档日志的最大序号吻合,说明switchover成功。
2. 物理standby执行failover
1). 检查standby归档文件是否连续
STANDBY>SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
no rows selected
这一步很重要,必须确保所有已生成的归档文件都已传到standby服务器。
如果上述语句有返回结果,则必须把缺失的归档文件从primary端复制到standby端,然后通过以下命令将其加入数据库:
STANDBY>alter database register physical logfile ' filespec'
2). 检查standby归档文件是否完整
STANDBY>SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY threa
d#) AS LAST from V$ARCHIVED_LOG;
THREAD LAST
---------- ----------
1 479
通过上述语句可以查出standby目前序号最大的归档日志为479,如果在primary端有比479更大的归档日志,把它们拷贝过来,然后通过以下命令将其加入数据库:
STANDBY>alter database register physical logfile ' filespec'
3)启动failover
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;
4)切换为primary
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
ALTER DATABASE OPEN;
STANDBY>select database_role from v$database;
DATABASE_ROLE
----------------
PRIMARY
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26277071/viewspace-709356/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26277071/viewspace-709356/