前一篇 Oracle DG 手动 SwitchOver & Failover,Failover后利用闪回恢复同步_Hehuyi_In的博客-CSDN博客介绍了SwitchOver & Failover的概念、区别及利用sql操作的方法。可以看到利用sql来执行需要在主从库均进行操作,命令也多,较为复杂,本篇来看如何利用DG Broker来简化这些操作。
注意:配置期间已有主从同步会中断,若当前从库已在使用,需要告知业务方,申请操作窗口
现有架构:以一主两备为例 | ||||
---|---|---|---|---|
数据库 IP | db_unique_name | 配置DG Broker时角色 | switchover后角色 | failover后角色 |
192.168.3.224 | prodcdb | 从库 | 主库 | 从库 |
192.168.3.225 | prodcdb_dg | 主库 | 从库 | 主库 |
192.168.3.226 | prodcdb_dg02 | 从库 | 从库 | 从库 |
DG Broker其实就是dgmgrl工具,安装Oracle数据库软件或完整的客户端都包含该工具,本文略。
按下面修改监听配置,如果不修改利用原有的监听也可以,后面会介绍这种方法
prodcdb_dg(主库)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = pdb_fsfo)
(SID_NAME = prodcdb)
)
(SID_DESC =
(GLOBAL_DBNAME = prodcdb)
(ORACLE_HOME = /data/prd/oracle/database/19.3.0.0/prod_cdb)
(SID_NAME = prodcdb)
)
(SID_DESC =
(GLOBAL_DBNAME = prodcdb_dg_DGMGRL) # 新增部分,名称为db_unique_name_DGMGRL
(ORACLE_HOME = /data/prd/oracle/database/19.3.0.0/prod_cdb)
(SID_NAME = prodcdb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.225)(PORT = 1521))
)
)
)
prodcdb(备库1)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = pdb_fsfo)
(SID_NAME = prodcdb)
)
(SID_DESC =
(GLOBAL_DBNAME = prodcdb)
(ORACLE_HOME = /data/prd/oracle/database/19.3.0.0/prod_cdb)
(SID_NAME = prodcdb)
)
(SID_DESC =
(GLOBAL_DBNAME = prodcdb_DGMGRL) # 新增部分,名称为db_unique_name_DGMGRL
(ORACLE_HOME = /data/prd/oracle/database/19.3.0.0/prod_cdb)
(SID_NAME = prodcdb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.224)(PORT = 1521))
)
)
)
prodcdb_dg02(备库2)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = pdb_fsfo)
(SID_NAME = prodcdb)
)
(SID_DESC =
(GLOBAL_DBNAME = prodcdb)
(ORACLE_HOME = /data/prd/oracle/database/19.3.0.0/prod_cdb)
(SID_NAME = prodcdb)
)
(SID_DESC =
(GLOBAL_DBNAME = prodcdb_dg02_DGMGRL) # 新增部分,名称为db_unique_name_DGMGRL
(ORACLE_HOME = /data/prd/oracle/database/19.3.0.0/prod_cdb)
(SID_NAME = prodcdb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.226)(PORT = 1521))
)
)
)
reload 监听生效,reload后应该能看到 _DGMGRL相关信息
lsnrctl reload
lsnrctl status
三个节点均需配置
# add for DGMGRL
prodcdb_DGMGRL=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.224)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prodcdb_DGMGRL)
)
)
prodcdb_dg_DGMGRL=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.225)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prodcdb_dg_DGMGRL)
)
)
prodcdb_dg02_DGMGRL=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.247)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prodcdb_dg02_DGMGRL)
)
)
三个节点均需配置,这步开始,已有主从同步会中断。
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_3='';
如果不清空,后面添加从库时会报错
DGMGRL> add database prodcdb as connect identifier is prodcdb_DGMGRL;
Error: ORA-16698: member has a LOG_ARCHIVE_DEST_n parameter with SERVICE attribute set Failed.
可以用默认的路径,也可以自己指定(三个节点均需配置)。如果是RAC环境,把这个文件把到共享存储或者ASM中。
SQL> show parameter dg_broker_config_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
dg_broker_config_file1 string /data/prd/oracle/database/19.3
.0.0/prod_cdb/dbs/dr1prodcdb.d
at
dg_broker_config_file2 string /data/prd/oracle/database/19.3
.0.0/prod_cdb/dbs/dr2prodcdb.d
at
三个节点均需配置
alter system set dg_broker_start=true;
任意节点执行即可,这里选择在主库(prodcdb_dg)执行
create configuration <配置名(随意)> as primary database is
dgmgrl
DGMGRL> connect sys/"xxxx"
DGMGRL> create configuration prodcdb_dgmgrl as primary database is prodcdb_dg connect identifier is prodcdb_dg_DGMGRL;
DGMGRL>enable configuration
-- 查看配置文件
DGMGRL> show configuration
add database <备库db_unique_name> as connect identifier is
DGMGRL> add database prodcdb as connect identifier is prodcdb_DGMGRL;
DGMGRL> add database prodcdb_dg02 as connect identifier is prodcdb_dg02_DGMGRL;
DGMGRL> enable database prodcdb;
DGMGRL> enable database prodcdb_dg02;
至此配置完成,可以查看配置和从库信息
DGMGRL> show configuration
Configuration - prodcdb_dgmgrl
Protection Mode: MaxPerformance
Members:
prodcdb_dg - Primary database
prodcdb - Physical standby database
prodcdb_dg02 - Physical standby database
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 59 seconds ago)
DGMGRL> show database prodcdb
Database - prodcdb
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 0 seconds ago)
Apply Lag: 0 seconds (computed 0 seconds ago)
Average Apply Rate: 6.00 KByte/s
Real Time Query: ON
Instance(s):
prodcdb
Database Status:
SUCCESS
DGMGRL> show database prodcdb
Database - prodcdb
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 0 seconds ago)
Apply Lag: 0 seconds (computed 0 seconds ago)
Average Apply Rate: 6.00 KByte/s
Real Time Query: ON
Instance(s):
prodcdb
DGMGRL> switchover to prodcdb;
DGMGRL> switchover to prodcdb;
Performing switchover NOW, please wait...
Operation requires a connection to database "prodcdb"
Connecting ...
Connected to "prodcdb"
Connected as SYSDBA.
New primary database "prodcdb" is opening...
Operation requires start up of instance "prodcdb" on database "prodcdb_dg"
Starting instance "prodcdb"...
Connected to an idle instance.
ORACLE instance started.
Connected to "prodcdb_dg"
Database mounted.
Database opened.
Connected to "prodcdb_dg"
Switchover succeeded, new primary is "prodcdb"
DGMGRL> show configuration
Configuration - prodcdb_dgmgrl
Protection Mode: MaxPerformance
Members:
prodcdb - Primary database
prodcdb_dg - Physical standby database
prodcdb_dg02 - Physical standby database
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 56 seconds ago)
发现SwitchOver已经成功完成了
DGMGRL> show database prodcdb_dg
Database - prodcdb_dg
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 1 second ago)
Apply Lag: 0 seconds (computed 1 second ago)
Average Apply Rate: 23.00 KByte/s
Real Time Query: ON
Instance(s):
prodcdb
Database Status:
SUCCESS
create table temp0315(a date);
begin
for i in 1 .. 1800 loop
insert into temp0315 values(sysdate);
commit;
DBMS_LOCK.SLEEP(1);
end loop;
end;
/
shutdown abort
DGMGRL> show database prodcdb_dg
Database - prodcdb_dg
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 59 seconds ago)
Apply Lag: 0 seconds (computed 59 seconds ago)
Average Apply Rate: 6.00 KByte/s
Real Time Query: ON
Instance(s):
prodcdb
Database Warning(s):
ORA-16857: member disconnected from redo source for longer than specified threshold
Database Status:
WARNING
DGMGRL> failover to prodcdb_dg;
DGMGRL> failover to prodcdb_dg
Performing failover NOW, please wait...
Failover succeeded, new primary is "prodcdb_dg"
DGMGRL> show configuration
Configuration - prodcdb_dgmgrl
Protection Mode: MaxPerformance
Members:
prodcdb_dg - Primary database
Warning: ORA-16857: member disconnected from redo source for longer than specified threshold
prodcdb - Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
prodcdb_dg02 - Physical standby database
Fast-Start Failover: Disabled
Configuration Status:
WARNING (status updated 93 seconds ago)
DGMGRL> show database prodcdb_dg02
Database - prodcdb_dg02
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 1 second ago)
Apply Lag: 0 seconds (computed 1 second ago)
Average Apply Rate: 5.00 KByte/s
Real Time Query: ON
Instance(s):
prodcdb
Database Status:
SUCCESS
补充:
如手工切换时failover有两类,使用DG Broker也有两种failover方法
DGMGRL> FAILOVER TO database-name;
# 或者
DGMGRL> FAILOVER TO database-name IMMEDIATE;
为使REINSTATE命令成功执行,故障转移之前必须已在原主库(新备库)上启用闪回,并且必须有足够的闪回和归档日志。
如果有开机自启动的,startup过程中会报错 ORA-16649: possible failover to another database prevents this database from being opened,会发现只能起到mount状态,没关系,继续后面的操作。
startup mount
连接到代理配置中的任何数据库(要恢复的数据库除外)时,执行:
DGMGRL> reinstate database prodcdb;
Reinstating database "prodcdb", please wait...
Reinstatement of database "prodcdb" succeeded
如果能完成,它将变为新主库的备库。如果失败,其状态将更改为 ORA-16795: the standby database needs to be re-created。那就没办法,只能重搭主从了。
DGMGRL> show configuration
Configuration - prodcdb_dgmgrl
Protection Mode: MaxPerformance
Members:
prodcdb_dg - Primary database
prodcdb - Physical standby database
prodcdb_dg02 - Physical standby database
Fast-Start Failover: Disabled
Configuration Status:
SUCCESS (status updated 47 seconds ago)
DGMGRL> show database prodcdb
Database - prodcdb
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 1 second ago)
Apply Lag: 0 seconds (computed 1 second ago)
Average Apply Rate: 14.00 KByte/s
Real Time Query: ON
Instance(s):
prodcdb
Database Status:
SUCCESS
参考
https://blog.csdn.net/shiyu1157758655/article/details/55504026
一步一步配置DataGuard Broker - 墨天轮
Oracle DG 手动 SwitchOver & Failover,Failover后利用闪回恢复同步_Hehuyi_In的博客-CSDN博客
Switchover and Failover Operations
Oracle Data Guard Broker Concepts