1. 查看switchover_status:
SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE;
2. 切换为备库
alter database commit to switchover to physical standby WITH SESSION SHUTDOWN;
alter database commit to switchover to physical standby;
注意:如果上一步的SWITCH_STATUS参数值为"TO STANDBY",则 WITH SESSION SHUTDOWN 可以省略。
3. 启动mount
SQL> SHUTDOWN ABORT
SQL> STARTUP MOUNT
注意:11.2.0.4版本及其以上版本不需要执行"SHUTDOWN ABORT",因为数据库已经在切换命令中关闭了。
4. 数据库状态
set line 600
SELECT DB_UNIQUE_NAME,DATABASE_ROLE,PROTECTION_MODE, SWITCHOVER_STATUS, OPEN_MODE FROM V$DATABASE;
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
备库
1. 备库状态
SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE;
注意:需要检查SWITCH_STATUS参数,如果值为"SESSION ACTIVE"或"TO PRIMARY",则备库可以切换为主库。
3. 提升主库
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
注意:如果上一步的SWITCH_STATUS参数值为"TO PRIMARY",则 WITH SESSION SHUTDOWN 可以省略。
4. 状态查看
SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE;
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
状态校验
查看数据库角色是否切换成功
select database_role from v$database;
查看DG进程是否正常
select process,status,thread#,sequence# from v$managed_standby;
查看同步延时
set pagesize 20;
column name format a13;
column value format a20;
column unit format a30;
column TIME_COMPUTED format a30;
select name,value,unit,time_computed from v$dataguard_stats where name in ('transport lag','apply lag');
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
二. failover
备库
在备库确认是否有日志没有同步:
SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
如果此查询有记录,需要把这些日志从主库拷贝到备库,并注册到数据库中:
ALTER DATABASE REGISTER PHYSICAL LOGFILE '拷贝过来的日志文件';
查询日志是否应用到最新状态:
select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log;
在备库做失败切换:
alter database recover managed standby database finish force;
alter database commit to switchover to primary;
alter database open;