标签:class serve level 逻辑 mount tag sage 切换方法 mode
和DG有关的角色:
角色切换的两种情况:
SYS@proe> select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM AVAILABILITY RESYNCHRONIZATION
SYS@proe>show parameter fal_server;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
fal_server string stddb
SYS@proe>show parameter db_file_name_convert;
NAME TYPE VALUE
------------------------------------ ----------- ----------------------
db_file_name_convert string /u01/app/oracle/oradata/stddb/,/u01/app/oracle/oradata/proe /
SYS@proe> show parameter log_archive_dest_2;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string service=stddb valid_for=(onlin
e_logfiles,primary_role) db_un
ique_name=stddb
SYS@stddb> show parameter log_archive_dest_2
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2 string service=stddb valid_for=(onlin
e_logfiles,primary_role) db_un
ique_name=pridb
[oracle@11g ~]$ tnsping stddb
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 22-JUL-2020 12:37:21
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11gtest)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stddb)))
OK (20 msec)
[oracle@11gtest ~]$ tnsping proe
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 19-JUL-2020 17:31:35
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11g)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = proe)))
OK (110 msec)
[oracle@11gtest ~]$ sqlplus sys/123456@proe as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Jul 19 17:33:18 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@proe>
[oracle@11g ~]$ sqlplus sys/123456@stddb as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 22 12:39:40 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@stddb>
注意:原则上至多只能有一个主库,但是备库可以多个,所以需要先进行主库转备库操作。
SYS@proe>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
------------------------- ---------------- --------------------
PROE PRIMARY TO STANDBY
SYS@proe>alter database commit to switchover to physical standby;
Database altered.
SYS@proe>shutdown abort
ORACLE instance shut down.
SYS@proe>startup mount;
ORACLE instance started.
# 查看此时角色切换状态
SYS@proe>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
------------------------- ---------------- --------------------
PROE PHYSICAL STANDBY RECOVERY NEEDED
# 查看角色保护模式和级别
SYS@proe> select name,database_role,protection_mode,protection_level from v$database;
NAME DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
------------------------- ---------------- -------------------- --------------------
PROE PHYSICAL STANDBY MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY
"TO STANDBY"意味着主库此时可以切换为备库,如果状态为SESSION ACTIVE可以使用以下命令切换。然后执行上述切换后的操作。
SYS@proe>alter database commit to switchover to physical standby with session shutdown;
SYS@stddb>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROE PHYSICAL STANDBY TO PRIMARY
SYS@stddb>alter database commit to switchover to primary;
Database altered.
# 查看此时角色切换状态
SYS@stddb>select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
PROE PRIMARY NOT ALLOWED
# 查看角色保护模式和级别
SYS@stddb>select name,database_role,protection_mode,protection_level from v$database;
NAME DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
--------- ---------------- -------------------- --------------------
PROE PRIMARY MAXIMUM PERFORMANCE UNPROTECTED
# 备库切换为主库后实例状态
SYS@stddb>select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
stddb MOUNTED
# 将数据库启动到open
SYS@stddb>alter database open;
Database altered.
# 再次查看转换后的角色保护模式及级别,可以看到和原来的主库一致。
SYS@stddb>select database_role,protection_mode,protection_level from v$database;
DATABASE_ROLE PROTECTION_MODE PROTECTION_LEVEL
---------------- -------------------- --------------------
PRIMARY MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE
原来的主库已经切换为备库,查看此时数据库打开模式
SYS@proe>select name,open_mode from v$database;
NAME OPEN_MODE
------------------------- --------------------
PROE MOUNTED
数据库启动到open
SYS@proe>alter database open;
Database altered.
启动数据库的日志应用服务
SYS@proe>alter database recover managed standby database using current logfile disconnect;
Database altered.
# 查看数据库打开模式
SYS@proe>select name,open_mode from v$database;
NAME OPEN_MODE
------------------------- --------------------
PROE READ ONLY WITH APPLY
一次完整的主备切换完成
标签:class serve level 逻辑 mount tag sage 切换方法 mode
原文地址:https://www.cnblogs.com/plutozzl/p/13360612.html