在前面的章节中,完成了单实例主库和rac物理备库的环境的构建,本节中将介绍下如何完成主备库的手动角色切换,在这个场合如果使用data guard broker进行切换,会由于crs的原因而切换失败,因为数据库还未向crs进行注册,回顾下在rac环境上的使用data guard broker的使用条件:在rac环境下还需要配置DB_BROKER_CONFIG_FILEn参数,将该参数指定共享存储上,需要在OCR中要设定start_options参数为mount;因而在本例中必须采用手动切换,在开始之前,需要确保主库和备库的日志应用正常!
一:查看主库和备库的switchover状态,同时关闭节点2数据库
SQL> select name,db_unique_name,open_mode,database_role,switchover_status from gv$database; NAME DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STAT [oracle@rac2 ~]$ sqlplus /nolog SQL> select name,db_unique_name,open_mode,database_role,switchover_status from gv$database; NAME DB_UNIQUE_ OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS |
二:primary数据库库上运行下列的命令后,重新将数据库启动到mount状态,并开启应用日志模式
SQL> alter database commit to switchover to physical standby with session shutdown; SQL> shutdown immediate SQL> startup mount SQL> select name,db_unique_name,open_mode,database_role,switchover_status from gv$database; NAME DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STAT SQL> alter database recover managed standby database cancel; |
三:将standby数据库转换为主库,出现下面的错误信息,需要手动rename下在线日志组
SQL> alter database commit to switchover to primary; SQL> alter system set db_create_file_dest='+DATA'; SQL> alter system set db_create_online_log_dest_1='+DATA'; SQL> alter system set standby_file_management=manual; SQL> alter database rename file '/u01/app/oracle/oradata/orcl/redo01.log' to '+DATA/ORCL/ONLINELOG/redo01.log'; SQL> alter system set standby_file_management=auto; SQL> alter database commit to switchover to primary; SQL> alter database open; SQL> select name,db_unique_name,open_mode,database_role,switchover_status from gv$database; NAME DB_UNIQUE_ OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS SQL> alter database recover managed standby database disconnect from session; SQL> select name,db_unique_name,open_mode,database_role,switchover_status from gv$database; NAME DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STAT |
[root@rac2 ~]# su - oracle SQL> conn /as sysdba Total System Global Area 213909504 bytes |
SQL> select name,db_unique_name,open_mode,database_role,switchover_status from gv$database; NAME DB_UNIQUE_ OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
OWNER TABLE_NAME SQL> select count(*) from test1.source; COUNT(*) SQL> select count(*) from test1.migrate; COUNT(*) SQL> select count(*) from test2.source2; COUNT(*) 节点1数据库实例: 节点2数据库实例: 备库: FIRST_TIME NEXT_TIME SEQUENCE# APP THREAD# FIRST_TIME NEXT_TIME SEQUENCE# APP THREAD# SQL> select first_time,next_time,sequence#,applied,thread# from v$archived_log where thread#=2 and sequence# >20 ; FIRST_TIME NEXT_TIME SEQUENCE# APP THREAD# 主库上切换日志测试日志是否能成功应用到备库 SQL> alter system archive log current; 备库查询: FIRST_TIME NEXT_TIME SEQUENCE# APP THREAD#
FIRST_TIME NEXT_TIME SEQUENCE# APP THREAD# FIRST_TIME NEXT_TIME SEQUENCE# APP THREAD# 主库建表测试,同时切换日志 SQL> alter system archive log current; 备库的alert日志摘要信息 将备库启动到只读状态,查看数据 SQL> alter database open read only; SQL> select * from test1.maa; A SQL> alter database recover managed standby database disconnect from session; |
六:收尾工作
SQL> @$ORACLE_HOME/rdbms/admin/catclust.sql; [oracle@rac1 ~]$ srvctl add database -d orcl -o $ORACLE_HOME |
本文出自 “斩月” 博客,谢绝转载!