共计 5341 个字符,预计需要花费 14 分钟才能阅读完成。
丸趣 TV 小编给大家分享一下 oracle 12c data guard 如何使用 sqlplus 主备切换,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
第一,切换之前的检查。确认备库已经准备好切换
确认备库与主库是同步的并且日志切换正常。
SQL alter database switchover to target standby db_unique_name verify;
以上命令会验证如下信息:
a. 验证数据库的版本至少为 12.1。
b. 主库 REDO 传输正常。
c. 备库 MRP 进程正常运行并且与主库同步,否则会在 SQLPROMPT 和 alert 中都报如下错误:
列如:
SQL alter database switchover to chicago verify;
ORA-16470: Redo Apply is not running on switchover target
——Primary alert log——
SQL alter database switchover to chicago verify;
ORA-16470 signaled during: alter database switchover to chicago verify…
在目标备库上检查 ORL 的状态
如果是脏的那么会报出如下信息:
SQL alter database switchover to chicago verify;
ERROR at line 1:
ORA-16475: succeeded with warnings, check alert log for more details
—–Primary Alert log———–
SWITCHOVER VERIFY WARNING: switchover target has dirty online redo logfiles that require clearing.
It takes time to clear online redo logfiles. This may slow down switchover process.
需要做什么呢?
确认 log_file_name_convert 参数在目标备库被正确设置:
SQL show parameter log_file_name_convert;
注意:如果没有设置,请设置。例如,如果路径结构只有 db_uniquq_name 发生了改变:
主库的日志在: /oradata/boston/
备库的日志在:/oradata/chicago/logfiles
这样设置参数:
alter system set LOG_FILE_NAME_CONVERT=’boston’,’chicago’scope=spfile;
注意:重启备库并且启动 MRP。当重启备库并且启动 MRP,将清除所有备库的 log_file_name_convert 参数设置的日志。
如果备库是与主库同步的,将得到如下的信息:
SQL alter database switchover to chicago verify;
Database altered.
——— Primary Alert log ——-
SWITCHOVER VERIFY: Send VERIFY request to switchover target CHICAGO
SWITCHOVER VERIFY COMPLETE
Completed: alter database switchover to chicago verify
确认主库和备库的临时数据文件匹配
临时数据文件在创建备库之后,不会同时创建临时数据文件,用如下的命令查询临时数据文件,并且在备库进行创建。
SQL col name for a45
SQL select ts#,name,ts#,status from v$tempfile;
注意:对于多个备库的环境,确保每个备库与主库同步。Check if log_archive_Dest(remote redo transport) set on Standby side
SWITCHOVER VERIFY command returns ORA-16475 when log_archive_dest_n is not set on Standby as follows.
SQL ALTER DATABASE SWITCHOVER TO S1202 VERIFY;
ALTER DATABASE SWITCHOVER TO S1202 VERIFY
*
ERROR at line 1:
ORA-16475: succeeded with warnings, check alert log for more details
In alert.log, following messages appear.
SWITCHOVER VERIFY: Send VERIFY request to switchover target S1202
SWITCHOVER VERIFY COMPLETE
SWITCHOVER VERIFY WARNING: switchover target has no standby database definedin LOG_ARCHIVE_DEST_n parameter. If the switchover target is converted to
a primary database, the new primary database will not be protected.ORA-16475 signalled during: ALTER DATABASE SWITCHOVER TO S1202 VERIFY…
What to do? set log_archive_dest_state_n on Standby.
如果 v$database 的 switchover_status 的值为 UNRESOLVABLE GAP(RAC 或者非 RAC)
1. 检查是否有些关闭的线程存在并且 disable
SQL SELECT thread#, instance, status FROM v$thread;
Disable 线程使用:
SQL ALTER DATABASE DISABLE THREAD n
2. 检查是否有 log_archive_destination 指向不合法的目录
SQL select status,DEST_ID,TYPE,ERROR,GAP_STATUS,SYNCHRONIZED,SYNCHRONIZATION_STATUS,RECOVERY_MODE from V$ARCHIVE_DEST_STATUS where STatus INACTIVE
SQL show parameter log_Archive_dest
第二,切换角色在主库和备库同时开启 trace,用于发生问题时候的诊断。
SQL alter system set log_archive_trace=8191 sid=’*’;
监视各个实例的 alert log(可选)
@primary and standby,
SQL show parameter background_dump_dest
$tail -600f background_dump_dest/alert*
* 注意: 在 RAC 环境不需要关闭其他的实例,执行 Switchover 的命令会关闭所有的实例。
切换备库角色为主库
主库 – Boston,
SQL alter database switchover to chicago;
Database altered.
以下是主库(BOSTON)和备库(CHICAGO)的 alert 输出:
————–Primary Alert log alert_boston.log ————–
Fri Aug 23 11:05:23 2013
ALTER SYSTEM SET log_archive_trace=8191 SCOPE=BOTH;
alter database switchover to chicago
Fri Aug 23 11:05:43 2013
Starting switchover [Process ID: 3340]
Fri Aug 23 11:05:43 2013
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY [Process Id: 3340] (boston)
.
Fri Aug 23 11:05:44 2013
Active, synchronized Physical Standby switchover target has been identified
Preventing updates and queries at the Primary
Generating and shipping final logs to target standby
Switchover End-Of-Redo Log thread 1 sequence 11 has been fixed ——— 序列号 11 是日志的终止序号
Switchover: Primary highest seen SCN set to 0x0.0x229306
ARCH: Noswitch archival of thread 1, sequence 11
.
Switchover: Primary controlfile converted to standby controlfile succesfully.
Switchover: Complete – Database shutdown required
Sending request (convert to primary database) to switchover target CHICAGO
OCISessionBegin with PasswordVerifier succeeded
Switchover complete. Database shutdown required
USER (ospid: 3340): terminating the instance
Fri Aug 23 11:05:51 2013
Instance terminated by USER, pid = 3340
Completed: alter database switchover to chicago
——————-alert log alert_chicago.log ——————
Fri Aug 23 11:05:47 2013
SWITCHOVER: received request ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY from primary database.
Fri Aug 23 11:05:47 2013
ALTER DATABASE SWITCHOVER TO PRIMARY (chicago)
Maximum wait for role transition is 15 minutes.
.
Standby became primary SCN: 2265860
Switchover: Complete – Database mounted as primary
SWITCHOVER: completed request from primary database.
注意:备库一端只等待 15 分钟,实现备库与主库的同步。
打开新的主数据库
SQL alter database open;
重启新的备库
SQL shut abort
SQL startup
SQL alter database recover managed standby database disconnect;
第三,切换后的后续步骤关闭 trace
SQL alter system set log_archive_trace=0;
System altered.
确认新的主库已经正常传输日志到备库,并且备库能正常应用。
在主库侧执行
SQL alter system switch logfile;
SQL select dest_id,error,status from v$archive_dest where dest_id= your remote log_archive_dest_ n ;
SQL select max(sequence#),thread# from v$log_history group by thread#;
如果备库端对应 log_archive_dest_2
SQL select max(sequence#) from v$archived_log where applied= YES and
dest_id=2;
在备库侧:
SQL select thread#,sequence#,process,status from gv$managed_standby;
SQL select max(sequence#),thread# from v$archived_log group by thread#;
注意:在 12.2 中使用 v$dataguard_process 替代 v$managed_standby
SQL select name,role,instance,thread#,sequence#,action from gv$dataguard_process;
以上是“oracle 12c data guard 如何使用 sqlplus 主备切换”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!