目录
1.Oracle 19c命令手动Switchover
1.1switchover主要步骤
要在 DataGuard 环境中执行 Switchover,我们必须执行以下步骤:
- 在当前主数据库上:
alter database switchover to
STANDBY_DB_UNIQUE_NAME;
- 在旧的备用数据库(新的主数据库)上:
alter database open;
- 在旧的主数据库(新备用数据库)上:
startup mount
alter database recover managed standby database disconnect from session;
2.命令执行切换switchover
我的环境:
ENV Detail | Primary | Standby |
---|---|---|
DB Unique | orcl | orcl_stby |
DB Name | orcl | orcl |
hostname:Server IP | db1:192.168.32.172 | db2:192.168.32.172 |
主库上检验备库
[oracle@db1 ~]$ sqlplus / as sysdba
SQL> alter database switchover to orcl_stdy verify;
Database altered.
#报错可以在告警日志中查看SWITCHOVER VERIFY关键字
#示例(这里我故意取消LOG_ARCHIVE_DEST配置,重新配置后恢复):
SQL> alter database switchover to orcl_stdy verify;
alter database switchover to orcl_stdy verify
*
ERROR at line 1:
ORA-16475: succeeded with warnings, check alert log for more details
日志vim /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log中:
SWITCHOVER VERIFY: Send VERIFY request to switchover target ORCL_STDY
SWITCHOVER VERIFY WARNING: switchover target has no standby database defined in LOG_ARCHIVE_DEST_n parameter. If the switchover target is converted to a primary database, the new primary database will not be protected.
主库开启切换
SQL> alter database switchover to orcl_stdy;
Database altered.
旧版本命令:
In previous releases this step was done in two commands:
- on Primary:
alter database commit to switchover to standby;
- on Standby:
alter database commit to switchover to primary;
主库切换日志:
2025-01-16T10:23:03.422463+08:00
alter database switchover to orcl_stdy
2025-01-16T10:23:03.422535+08:00
NET (PID:3859): The Time Management Interface (TMI) is being enabled for role transition
NET (PID:3859): information. This will result in messages beingoutput to the alert log
NET (PID:3859): file with the prefix 'TMI: '. This is being enabled to make the timing of
NET (PID:3859): the various stages of the role transition available for diagnostic purposes.
NET (PID:3859): This output will end when the role transition is complete.
TMI: dbsdrv switchover to target BEGIN 2025-01-16 10:23:03.422825
NET (PID:3859): Starting switchover [Process ID: 3859]
TMI: kcv_switchover_to_target convert to physical BEGIN 2025-01-16 10:23:03.512708
2025-01-16T10:23:03.512873+08:00
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY [Process Id: 3859] (orcl)
NET (PID:3859): Waiting for target standby to receive all redo
2025-01-16T10:23:03.514556+08:00
NET (PID:3859): Waiting for all non-current ORLs to be archived
2025-01-16T10:23:03.514658+08:00
NET (PID:3859): All non-current ORLs have been archived
2025-01-16T10:23:03.514749+08:00
NET (PID:3859): Waiting for all FAL entries to be archived
2025-01-16T10:23:03.514809+08:00
NET (PID:3859): All FAL entries have been archived
2025-01-16T10:23:03.514907+08:00
NET (PID:3859): Waiting for LAD:2 to become synchronized
2025-01-16T10:23:04.515416+08:00
NET (PID:3859): Active, synchronized Physical Standby switchover target has been identified
NET (PID:3859): Preventing updates and queries at the Primary
2025-01-16T10:23:05.516382+08:00
NET (PID:3859): Generating and shipping final logs to target standby
Switchover End-Of-Redo Log thread 1 sequence 62 has been fixed
Switchover: Primary highest seen SCN set to 0x0000000000328170
NET (PID:3859): Noswitch archival of T-1.S-62
NET (PID:3859): End-Of-Redo Branch archival of T-1.S-62
NET (PID:3859): LGWR is scheduled to archive to LAD:2 after log switch
NET (PID:3859): SRL selected for T-1.S-62 for LAD:2
NET (PID:3859): Archiving is disabled due to current logfile archival
Primary will check for some target standby to have received all redo
NET (PID:3859): Waiting for target standby to apply all redo
Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_3859.trc
NET (PID:3859): Converting the primary database to a new standby database
Clearing standby activation ID 1716972720 (0x6656ecb0)
The primary database controlfile was created using the
'MAXLOGFILES 16' clause.
There is space for up to 13 standby redo logfiles
Use the following SQL commands on the standby database to create
standby redo logfiles that match the primary database:
ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 209715200;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 209715200;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 209715200;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 209715200;
Archivelog for thread 1 sequence 62 required for standby recovery
Offline data file 5 marked as online during convert to standby or switchover to standby.
Restore of backup may be required if the file is not physically accessible.
Offline data file 6 marked as online during convert to standby or switchover to standby.
Restore of backup may be required if the file is not physically accessible.
Offline data file 8 marked as online during convert to standby or switchover to standby.
Restore of backup may be required if the file is not physically accessible.
Offline data file 9 marked as online during convert to standby or switchover to standby.
Restore of backup may be required if the file is not physically accessible.
Offline data file 10 marked as online during convert to standby or switchover to standby.
Restore of backup may be required if the file is not physically accessible.
Offline data file 11 marked as online during convert to standby or switchover to standby.
Restore of backup may be required if the file is not physically accessible.
Offline data file 12 marked as online during convert to standby or switchover to standby.
Restore of backup may be required if the file is not physically accessible.
Switchover: Primary controlfile converted to standby controlfile succesfully.
Switchover: Complete - Database shutdown required
TMI: kcv_switchover_to_target convert to physical END 2025-01-16 10:23:05.834689
NET (PID:3859): Sending request(convert to primary database) to switchover target ORCL_STDY
2025-01-16T10:23:16.333104+08:00
NET (PID:3859): Switchover complete. Database shutdown required
USER (ospid: 3859): terminating the instance
2025-01-16T10:23:17.356528+08:00
Instance terminated by USER, pid = 3859
TMI: dbsdrv switchover to target END 2025-01-16 10:23:17.356548
Completed: alter database switchover to orcl_stdy
Shutting down ORACLE instance (abort) (OS id: 3859)
License high water mark = 15
2025-01-16T10:23:17.448848+08:00
Instance shutdown complete (OS id: 3859)
备库切换日志:
SWITCHOVER: received request 'ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY' from primary database.
2025-01-16T10:23:05.674778+08:00
ALTER DATABASE SWITCHOVER TO PRIMARY (orcl)
Maximum wait for role transition is 15 minutes.
TMI: kcv_commit_to_so_to_primary wait for MRP to finish BEGIN 2025-01-16 10:23:05.679175
Switchover: Media recovery is still active
rmi (PID:22584): Role Change: Canceling MRP - no more redo to apply
2025-01-16T10:23:05.687106+08:00
......................................
......................................
......................................
2025-01-16T10:23:14.927420+08:00
CLOSE: all sessions shutdown successfully.
alter pluggable database all close
Completed: alter pluggable database all close
PDB$SEED(2):JIT: pid 22584 requesting stop
PDB$SEED(2):Buffer Cache flush deferred for PDB 2
2025-01-16T10:23:15.949594+08:00
IM on ADG: Start of Empty Journal
IM on ADG: End of Empty Journal
Stopping Emon pool
Buffer Cache invalidation for all PDBs started
Buffer Cache invalidation for all PDBs complete
Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/orcl_stdy/orcl/trace/orcl_rmi_22584.trc
SwitchOver after complete recovery through change 3309936
rmi (PID:22584): ORL pre-clearing operation disabled by switchover
Online log /u01/app/oracle/oradata/ORCL_STDY/onlinelog/o1_mf_1_mqgon8wp_.log: Thread 1 Group 1 was previously cleared
Online log /u01/app/oracle/fast_recovery_area/ORCL_STDY/onlinelog/o1_mf_1_mqgon902_.log: Thread 1 Group 1 was previously cleared
Online log /u01/app/oracle/oradata/ORCL_STDY/onlinelog/o1_mf_2_mqgoncbc_.log: Thread 1 Group 2 was previously cleared
Online log /u01/app/oracle/fast_recovery_area/ORCL_STDY/onlinelog/o1_mf_2_mqgoncf0_.log: Thread 1 Group 2 was previously cleared
Online log /u01/app/oracle/oradata/ORCL_STDY/onlinelog/o1_mf_3_mqgongc0_.log: Thread 1 Group 3 was previously cleared
Online log /u01/app/oracle/fast_recovery_area/ORCL_STDY/onlinelog/o1_mf_3_mqgongg7_.log: Thread 1 Group 3 was previously cleared
Standby became primary SCN: 3309934
rmi (PID:22584): RT: Role transition work is not done
rmi (PID:22584): The Time Management Interface (TMI) is being enabled for role transition
rmi (PID:22584): information. This will result in messages beingoutput to the alert log
rmi (PID:22584): file with the prefix 'TMI: '. This is being enabled to make the timing of
rmi (PID:22584): the various stages of the role transition available for diagnostic purposes.
rmi (PID:22584): This output will end when the role transition is complete.
rmi (PID:22584): Redo network throttle feature is disabled at mount time
AUDIT_TRAIL initialization parameter is changed back to its original value as specified in the parameter file.
2025-01-16T10:23:16.080372+08:00
rmi (PID:22584): Database role cleared from PHYSICAL STANDBY [kcvs.c:1030]
Switchover: Complete - Database mounted as primary
TMI: kcv_commit_to_so_to_primary Switchover from physical END 2025-01-16 10:23:16.080538
SWITCHOVER: completed request from primary database.
新主库(原备库)启动
#日志中可以看到,已经是Mount ---Switchover: Complete - Database mounted as primary
[oracle@db2 ~]$ sqlplus / as sysdba
SQL> alter database open;
Database altered.
#PDB别忘了启动
SQL> alter pluggable database PDB1 open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
新主库已经可以用了
旧主库(新备库)恢复
[oracle@db1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jan 16 10:39:52 2025
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1526723568 bytes
Fixed Size 9135088 bytes
Variable Size 956301312 bytes
Database Buffers 553648128 bytes
Redo Buffers 7639040 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
#open
#ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
验证新的数据库角色
旧主库(新备库)
可以验证以前的主数据库的当前状态现在是 Physical Standby:
[oracle@db1 ~]$ sqlplus / as sysdba
SQL> select name,open_mode,database_role,switchover_status from v$database ;
NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------- -------------------- ---------------- --------------------
ORCL MOUNTED PHYSICAL STANDBY NOT ALLOWED
新主库(原备库)
我们可以看到以前的 Standby 数据库的当前状态现在是 Primary:
SQL> select name,open_mode,database_role,switchover_status from v$database ;
NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------- -------------------- ---------------- --------------------
ORCL READ WRITE PRIMARY TO STANDBY
3.回切
恢复到切换之前
在新主库(原备库)上switchover切换
检测
#在新主库(原备库)上
SQL> alter database switchover to orcl verify;
alter database switchover to orcl verify
*
ERROR at line 1:
ORA-16475: succeeded with warnings, check alert log for more details
---------------------------------------------------------------------------------
#这是由于我未设置log_file_name_convert导致
SQL> alter system set db_file_name_convert='/STBYDB/','/PRMYDB/' scope=spfile;
SQL> alter system set log_file_name_convert='/STBYDB/','/PRMYDB/' scope=spfile;
#在告警日志中:
SWITCHOVER VERIFY: Send VERIFY request to switchover target ORCL
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.
ORA-16475 signalled during: alter database switchover to orcl verify...
#懒得配置,直接忽略了,不影响,清理redo可能会稍慢
切换
SQL> alter database switchover to orcl;
Database altered.
打开主库(原主库)
[oracle@db1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jan 16 11:14:03 2025
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> alter database open;
Database altered.
SQL> alter pluggable database PDB1 open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
SQL> select name,open_mode,database_role,switchover_status from v$database ;
NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------- -------------------- ---------------- --------------------
ORCL READ WRITE PRIMARY TO STANDBY
恢复备库
[oracle@db2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jan 16 11:15:44 2025
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1526723568 bytes
Fixed Size 9135088 bytes
Variable Size 889192448 bytes
Database Buffers 620756992 bytes
Redo Buffers 7639040 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select name,open_mode,database_role,switchover_status from v$database ;
NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------- -------------------- ---------------- --------------------
ORCL MOUNTED PHYSICAL STANDBY NOT ALLOWED
###################
#open
数据测试
SQL> select name,open_mode,database_role,switchover_status from v$database ;
NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------- -------------------- ---------------- --------------------
ORCL READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED
标签:Switchover,switchover,database,standby,DG,PID,2025,Oracle,3859
From: https://www.cnblogs.com/shipment/p/18674678