物理DG主备切换小结
环境检查
检查两RAC的参数文件配置
SQL> show parameter spfile;
SQL>show parameter fal;
lsnrctl status 查看RAC环境中监听状态
tnsping 查看TNS的连通情况
如果需要RAC作为备库执行如下步骤
①.为RAC环境添加standby redolog,而且作为备库redolog group数要多于或等于主库:
SQL>alter database add standby logfile thread 1 group 5 size 50M ,group 6 size 50M ,group 7 size 50M ;
单实例添加方法:
SQL>alter database add standby logfile group 7 '/oradata/racdb/onlinelog/group_7.log' size 50M;
②.配置RAC环境中以下两个参数指定到自己的文件路径
SQL> alter system set db_file_name_convert='+DATA/phydb/','+DATA/racdb/' sid='*' scope=spfile;
SQL> alter system set log_file_name_convert='+DATA/phydb/','+DATA/racdb/' sid='*' scope=spfile;
检查standby数据库
SQL> select status from v$instance;
SQL> select open_mode from v$database;
SQL> select member from v$logfile;
如果没有standby redolog需要创建,语法如下:
SQL>alter database add standby logfile group 7 '/oradata/racdb/onlinelog/group_7.log' size 50M;
SQL> select name from v$datafile;
SQL> select name from v$tempfile;
SQL> show parameter control;
正常切换
①. 切换前检查RAC环境中数据库状态
SQL> select dbid,name,protection_mode,database_role,open_mode,switchover_status from gv$database;
关闭任一节点数据库
SQL> shutdown immediate;
②.将主库切换为备库
SQL>alter database commit to switchover to physical standby with session shutdown;
切换过程中查看数据库状态
③.备库将已经完成传输的日志应用完成,确保数据不会丢失
SQL> alter database recover managed standby database disconnect from session;
SQL> select name,creator,sequence#,applied,completion_time from v$archived_log;
SQL> alter database recover managed standby database cancel;
④. 断开所有连接会话(或者重启备库到mount状态),切换至主库
SQL> alter database commit to switchover to primary;(mount状态)
⑤.打开数据库,查看新主库的状态是否正常
SQL>alter database open;
SQL> select dbid,name,protection_mode,database_role,open_mode,switchover_status from v$database;
主库故障无法修复,快速切换备库为主库
启动备库到mount状态,查看数据库standby信息:
SQL>startup mount;
启动日志应用,确保最大限度的可以日志应用完成后,再开始切换
SQL> alter database recover managed standby database disconnect from session;
SQL> select name,creator,sequence#,applied,completion_time from v$archived_log;
SQL> alter database recover managed standby database cancel;
SQL>select thread#,low_sequence#,high_sequence from v$archive_gap;
确保日志传输完成,如果有返回记录,需要去主库上将该文件copy至备库相应目录下,并执行以下语句使之生效
SQL> alter database register physical logfile 'filespecl';
主备库上都查询一下归档的最大序列号,确保主库的归档备库上都有,如果发现备库没有的,需要手动的复制至备库。查询语句如下:
SQL> select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log;
停止当前的RFS进程,并立即执行failover
SQL> alter database recover managed standby database finish force;
切换备库为主库,并打开数据库
SQL> alter database commit to switchover to primary;
SQL> alter database open;
--------------------------------------分割线 --------------------------------------
--------------------------------------分割线 --------------------------------------