当前位置: 首页 > news >正文

Oracle dgbroker常规命令管理简介

Oracle dgbroker常规命令管理简介

在前面的文章中已经部署好了Oracle 19c ADG环境,并配置了db broker管理。

在这里简单介绍下dg broker的基本管理和使用。

1、登录db broker

[oracle@mgrser1 admin]$ dgmgrl
DGMGRL for Linux: Release 19.0.0.0.0 - Production on Tue Nov 4 02:56:28 2025
Version 19.3.0.0.0Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys@woo_dgmgrl
Password:
Connected to "woo"
Connected as SYSDBA.
DGMGRL> 

2、查看主备数据库信息

DGMGRL> show configuration;Configuration - woo_broker_cfgProtection Mode: MaxPerformanceMembers:woo    - Primary databasewoostd - Physical standby database Fast-Start Failover:  DisabledConfiguration Status:
SUCCESS   (status updated 7 seconds ago)DGMGRL> DGMGRL> show database woo;Database - wooRole:               PRIMARYIntended State:     TRANSPORT-ONInstance(s):wooDatabase Status:
SUCCESSDGMGRL> 
DGMGRL> show database woostd;Database - woostdRole:               PHYSICAL STANDBYIntended State:     APPLY-ONTransport Lag:      0 seconds (computed 1 second ago)Apply Lag:          0 seconds (computed 1 second ago)Average Apply Rate: 24.00 KByte/sReal Time Query:    ONInstance(s):wooDatabase Status:
SUCCESSDGMGRL> 

3、查看ADG同步延迟


DGMGRL> 
DGMGRL> show database woostd;Database - woostdRole:               PHYSICAL STANDBYIntended State:     APPLY-ONTransport Lag:      0 seconds (computed 1 second ago)Apply Lag:          0 seconds (computed 1 second ago)  <<<<Average Apply Rate: 24.00 KByte/sReal Time Query:    ONInstance(s):wooDatabase Status:
SUCCESS  <<<

4、查看详细信息包括日志文件

DGMGRL> show database verbose woo;Database - wooRole:               PRIMARYIntended State:     TRANSPORT-ONInstance(s):wooProperties:DGConnectIdentifier             = 'woo_dgmgrl'ObserverConnectIdentifier       = ''FastStartFailoverTarget         = ''PreferredObserverHosts          = ''LogShipping                     = 'ON'RedoRoutes                      = ''LogXptMode                      = 'ASYNC'DelayMins                       = '0'Binding                         = 'optional'MaxFailure                      = '0'ReopenSecs                      = '300'NetTimeout                      = '30'RedoCompression                 = 'DISABLE'PreferredApplyInstance          = ''ApplyInstanceTimeout            = '0'ApplyLagThreshold               = '30'TransportLagThreshold           = '30'TransportDisconnectedThreshold  = '30'ApplyParallel                   = 'AUTO'ApplyInstances                  = '0'StandbyFileManagement           = ''ArchiveLagTarget                = '0'LogArchiveMaxProcesses          = '0'LogArchiveMinSucceedDest        = '0'DataGuardSyncLatency            = '0'LogArchiveTrace                 = '0'LogArchiveFormat                = ''DbFileNameConvert               = ''LogFileNameConvert              = ''ArchiveLocation                 = ''AlternateLocation               = ''StandbyArchiveLocation          = ''StandbyAlternateLocation        = ''InconsistentProperties          = '(monitor)'InconsistentLogXptProps         = '(monitor)'LogXptStatus                    = '(monitor)'SendQEntries                    = '(monitor)'RecvQEntries                    = '(monitor)'HostName                        = 'mgrser1'StaticConnectIdentifier         = '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.104)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=woo_DGMGRL)(INSTANCE_NAME=woo)(SERVER=DEDICATED)))'TopWaitEvents                   = '(monitor)'SidName                         = '(monitor)'Log file locations:Alert log               : /oradb/oracle/diag/rdbms/woo/woo/trace/alert_woo.logData Guard Broker log   : /oradb/oracle/diag/rdbms/woo/woo/trace/drcwoo.logDatabase Status:
SUCCESSDGMGRL> DGMGRL> show database verbose woostd;Database - woostdRole:               PHYSICAL STANDBYIntended State:     APPLY-ONTransport Lag:      0 seconds (computed 1 second ago)Apply Lag:          0 seconds (computed 1 second ago)Average Apply Rate: 21.00 KByte/sActive Apply Rate:  0 Byte/sMaximum Apply Rate: 0 Byte/sReal Time Query:    ONInstance(s):wooProperties:DGConnectIdentifier             = 'woostd_dgmgrl'ObserverConnectIdentifier       = ''FastStartFailoverTarget         = ''PreferredObserverHosts          = ''LogShipping                     = 'ON'RedoRoutes                      = ''LogXptMode                      = 'ASYNC'DelayMins                       = '0'Binding                         = 'optional'MaxFailure                      = '0'ReopenSecs                      = '300'NetTimeout                      = '30'RedoCompression                 = 'DISABLE'PreferredApplyInstance          = ''ApplyInstanceTimeout            = '0'ApplyLagThreshold               = '30'TransportLagThreshold           = '30'TransportDisconnectedThreshold  = '30'ApplyParallel                   = 'AUTO'ApplyInstances                  = '0'StandbyFileManagement           = ''ArchiveLagTarget                = '0'LogArchiveMaxProcesses          = '0'LogArchiveMinSucceedDest        = '0'DataGuardSyncLatency            = '0'LogArchiveTrace                 = '0'LogArchiveFormat                = ''DbFileNameConvert               = ''LogFileNameConvert              = ''ArchiveLocation                 = ''AlternateLocation               = ''StandbyArchiveLocation          = ''StandbyAlternateLocation        = ''InconsistentProperties          = '(monitor)'InconsistentLogXptProps         = '(monitor)'LogXptStatus                    = '(monitor)'SendQEntries                    = '(monitor)'RecvQEntries                    = '(monitor)'HostName                        = 'mgrser2'StaticConnectIdentifier         = '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.105)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=WOOSTD_DGMGRL)(INSTANCE_NAME=woo)(SERVER=DEDICATED)))'TopWaitEvents                   = '(monitor)'SidName                         = '(monitor)'Log file locations:Alert log               : /oradb/oracle/diag/rdbms/woostd/woo/trace/alert_woo.logData Guard Broker log   : /oradb/oracle/diag/rdbms/woostd/woo/trace/drcwoo.logDatabase Status:
SUCCESSDGMGRL> 

5、使用DG Broker管理日志传输

关闭到备库的日志传输

DGMGRL> edit database 'woo' set state='TRANSPORT-OFF';
Succeeded.
DGMGRL> show database woo;Database - wooRole:               PRIMARYIntended State:     TRANSPORT-OFF   <<<<<<Instance(s):wooDatabase Status:
SUCCESSDGMGRL> 

查看主库的LNS进程


SQL> select process,status,thread#,sequence# from v$managed_standby where process like 'LNS%';PROCESS   STATUS          THREAD#  SEQUENCE#
--------- ------------ ---------- ----------
LNS       WRITING               1         34SQL> --再次查看   
SQL> /PROCESS   STATUS          THREAD#  SEQUENCE#
--------- ------------ ---------- ----------
LNS       WRITING               1         34SQL> /PROCESS   STATUS          THREAD#  SEQUENCE#
--------- ------------ ---------- ----------
LNS       WRITING               1         34SQL> alter system switch logfile;System altered.SQL> select process,status,thread#,sequence# from v$managed_standby where process like 'LNS%';no rows selectedSQL> 

查看主库上的log_archive_dest_state_n参数

SQL> show parameter log_archive_dest_state_2NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_2             string      RESET  <<<<<<<<<<<<
log_archive_dest_state_20            string      enable
log_archive_dest_state_21            string      enable
log_archive_dest_state_22            string      enable
log_archive_dest_state_23            string      enable
log_archive_dest_state_24            string      enable
log_archive_dest_state_25            string      enable
log_archive_dest_state_26            string      enable
log_archive_dest_state_27            string      enable
log_archive_dest_state_28            string      enable
log_archive_dest_state_29            string      enable
SQL> 

查看备库日志状态正等待35号

SQL> select process,status,sequence# from v$managed_standby;PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
DGRD      ALLOCATED             0
DGRD      ALLOCATED             0
ARCH      CONNECTED             0
ARCH      CLOSING              33
ARCH      CLOSING              34
RFS       IDLE                  0
MRP0      WAIT_FOR_LOG         358 rows selected.

回复到备库的日志同步

DGMGRL> 
DGMGRL> edit database 'woo' set state='TRANSPORT-ON';
Succeeded.
DGMGRL> show database woo;Database - wooRole:               PRIMARYIntended State:     TRANSPORT-ONInstance(s):wooDatabase Status:
SUCCESSDGMGRL> SQL> select process,status,sequence# from v$managed_standby;PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
DGRD      ALLOCATED             0
DGRD      ALLOCATED             0
ARCH      CLOSING              35
ARCH      CLOSING              33
ARCH      CLOSING              34
RFS       IDLE                 36
RFS       IDLE                  0
RFS       IDLE                  0
MRP0      APPLYING_LOG         36  <<<<< c重新开始应用日志了10 rows selected.SQL> --主库LNS进程也恢复了
SQL> select process,status,thread#,sequence# from v$managed_standby where process like 'LNS%';PROCESS   STATUS          THREAD#  SEQUENCE#
--------- ------------ ---------- ----------
LNS       WRITING               1         36SQL> 
SQL> show parameter log_archive_dest_state_2NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_state_2             string      ENABLE <<<<<<
log_archive_dest_state_20            string      enable
log_archive_dest_state_21            string      enable
log_archive_dest_state_22            string      enable
log_archive_dest_state_23            string      enable
log_archive_dest_state_24            string      enable
log_archive_dest_state_25            string      enable
log_archive_dest_state_26            string      enable
log_archive_dest_state_27            string      enable
log_archive_dest_state_28            string      enable
log_archive_dest_state_29            string      enable
SQL> 
SQL> 

DG Broker控制redo传输是通过修改主库的log_archive_dest_state_n参数来实现的。

关闭到指定备库的redo传输
将备库的LogShipping属性设置为OFF来暂停对该备库的日志传输:

show database woostd logshipping;edit database 'woostd' set property LogShipping='OFF';edit database 'woostd' set property LogShipping='ON';

6、物理备库和逻辑备库之间的转换

使用DG Broker管理备库
通过DG Broker可以方便地将备库在只读的物理备库模式和可读写的快照备库模式之间转换。在快照备库模式下对备库的写操作是暂时性的,当备库切回物理备库模式时,这些写操作会全部回滚。物理备库转换为快照备库的前提是备库开启了快速闪回区(Fast Recovery Area)。

DGMGRL> CONVERT DATABASE 'woostd' TO SNAPSHOT STANDBY;
Converting database "woostd" to a Snapshot Standby database, please wait...
Database "woostd" converted successfully
DGMGRL> 
SQL> set line 200
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;DB_UNIQUE_NAME                 OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS
------------------------------ -------------------- ---------------- --------------------
WOOSTD                         READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWEDSQL> 
SQL> 
SQL> 
SQL> --check again
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
select db_unique_name,open_mode,database_role,switchover_status from v$database
*
ERROR at line 1:
ORA-03135: connection lost contact
Process ID: 1635
Session ID: 1 Serial number: 27414SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@mgrser2 ~]$ sqlplus / as sysdbaSQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 4 03:21:07 2025
Version 19.3.0.0.0Copyright (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.0SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;DB_UNIQUE_NAME                 OPEN_MODE            DATABASE_ROLE
------------------------------ -------------------- ----------------
SWITCHOVER_STATUS
--------------------
WOOSTD                         READ WRITE           SNAPSHOT STANDBY
NOT ALLOWEDSQL> set line 200
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;DB_UNIQUE_NAME                 OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS
------------------------------ -------------------- ---------------- --------------------
WOOSTD                         READ WRITE           SNAPSHOT STANDBY NOT ALLOWEDSQL> 
SQL> SQL> set line 200
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;DB_UNIQUE_NAME                 OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS
------------------------------ -------------------- ---------------- --------------------
WOOSTD                         READ WRITE           SNAPSHOT STANDBY NOT ALLOWEDSQL> 
SQL>  create table elden_npc(npc_id number(6), name varchar2(30), career varchar2(20));Table created.  <<<<< 备库可读写SQL> drop table elden_npc purge;Table dropped.SQL> create table dgmgrtab(did number(6), name varchar2(30), career varchar2(20));Table created.SQL> 
SQL> insert into dgmgrtab values (1, 'dgmgr', 'abc');1 row created.SQL> 
SQL> commit;Commit complete.

转换备库为只读物理备库
尝试切换快照备库为物理备库:

DGMGRL> show database woostd;Database - woostdRole:               SNAPSHOT STANDBYTransport Lag:      0 seconds (computed 1 second ago)Apply Lag:          5 minutes 30 seconds (computed 1 second ago)  <<<< 在操作过程中主库的数据并未同步到备库Instance(s):wooDatabase Status:
SUCCESSDGMGRL> CONVERT DATABASE 'woostd' TO PHYSICAL STANDBY;     <<<<< 重新切换到物理备库
Converting database "woostd" to a Physical Standby database, please wait...
Operation requires shut down of instance "woo" on database "woostd"
Shutting down instance "woo"...
Connected to "WOOSTD"
Database closed.
Database dismounted.
ORACLE instance shut down.
Operation requires start up of instance "woo" on database "woostd"
Starting instance "woo"...
Connected to an idle instance.
ORACLE instance started.
Connected to "WOOSTD"
Database mounted.
Connected to "WOOSTD"
Continuing to convert database "woostd" ...
Database "woostd" converted successfully
DGMGRL> 

SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
select db_unique_name,open_mode,database_role,switchover_status from v$database
*   <<<<<<<<<< 重新切换物理备库后要重新登录一次数据库
ERROR at line 1:
ORA-03135: connection lost contact
Process ID: 3963
Session ID: 63 Serial number: 55232SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@mgrser2 ~]$ sqlplus / as sysdbaSQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 4 03:26:35 2025
Version 19.3.0.0.0Copyright (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.0SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;DB_UNIQUE_NAME                 OPEN_MODE            DATABASE_ROLE
------------------------------ -------------------- ----------------
SWITCHOVER_STATUS
--------------------
WOOSTD                         READ ONLY WITH APPLY PHYSICAL STANDBY
NOT ALLOWEDSQL> set line 200
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;DB_UNIQUE_NAME                 OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS
------------------------------ -------------------- ---------------- --------------------
WOOSTD                         READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWEDSQL> select * from dgmgrtab;   <<<<<<< 可以看到,快照备库期间写入的数据已经回滚了。
select * from dgmgrtab*
ERROR at line 1:
ORA-00942: table or view does not existSQL> 
SQL> 
SQL> 

7、使用DG Broker进行主备切换

检查是否可以进行切换:

DGMGRL> validate database woostd;Database Role:     Physical standby databasePrimary Database:  wooReady for Switchover:  YesReady for Failover:    Yes (Primary Running)Flashback Database Status:woo   :  Offwoostd:  OffManaged by Clusterware:woo   :  NO             woostd:  NO             Validating static connect identifier for the primary database woo...The static connect identifier allows for a connection to database "woo".DGMGRL> validate database woo;Database Role:    Primary databaseReady for Switchover:  Yes  <<<<<<<<<<<Flashback Database Status:woo:  OffManaged by Clusterware:woo:  NO             Validating static connect identifier for the primary database woo...The static connect identifier allows for a connection to database "woo".DGMGRL> 

切换前查看主备角色

--主库
SQL> col host_name for a30
SQL> select a.host_name,b.database_role from v$instance a,v$database b;HOST_NAME                      DATABASE_ROLE
------------------------------ ----------------
mgrser1                        PRIMARY--备库
SQL> col host_name for a30
SQL> select a.host_name,b.database_role from v$instance a,v$database b;HOST_NAME                      DATABASE_ROLE
------------------------------ ----------------
mgrser2                        PHYSICAL STANDBY

开始切换
switchover to woostd(计划需要成为主库角色的唯一名);

DGMGRL> switchover to woostd;
Performing switchover NOW, please wait...
Operation requires a connection to database "woostd"
Connecting ...
Connected to "WOOSTD"
Connected as SYSDBA.
New primary database "woostd" is opening...
Operation requires start up of instance "woo" on database "woo"
Starting instance "woo"...
Connected to an idle instance.
ORACLE instance started.
Connected to "woo"
Database mounted.
Database opened.
Connected to "woo"
Switchover succeeded, new primary is "woostd"
DGMGRL> 
DGMGRL> 
DGMGRL> 

再次查询主备库状态

--原主库角色
SQL> --check again
SQL> 
SQL> select a.host_name,b.database_role from v$instance a,v$database b;
select a.host_name,b.database_role from v$instance a,v$database b
*
ERROR at line 1:
ORA-03135: connection lost contact
Process ID: 3476
Session ID: 103 Serial number: 16969SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@mgrser1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 4 03:38:24 2025
Version 19.3.0.0.0Copyright (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.0SQL> select a.host_name,b.database_role from v$instance a,v$database b;HOST_NAME
----------------------------------------------------------------
DATABASE_ROLE
----------------
mgrser1
PHYSICAL STANDBYSQL> --原备库角色
SQL> select a.host_name,b.database_role from v$instance a,v$database b;
select a.host_name,b.database_role from v$instance a,v$database b
*
ERROR at line 1:
ORA-03135: connection lost contact
Process ID: 4379
Session ID: 67 Serial number: 27229SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@mgrser2 ~]$ sqlplus / as sysdbaSQL*Plus: Release 19.0.0.0.0 - Production on Tue Nov 4 03:38:35 2025
Version 19.3.0.0.0Copyright (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.0SQL> select a.host_name,b.database_role from v$instance a,v$database b;HOST_NAME
----------------------------------------------------------------
DATABASE_ROLE
----------------
mgrser2
PRIMARYDGMGRL> show configuration;Configuration - woo_broker_cfgProtection Mode: MaxPerformanceMembers:woostd - Primary database   <<<<<  角色已经调换woo    - Physical standby database Fast-Start Failover:  DisabledConfiguration Status:
SUCCESS   (status updated 60 seconds ago)DGMGRL> 

回切正常

DGMGRL> 
DGMGRL> switchover to woo;
Performing switchover NOW, please wait...
Operation requires a connection to database "woo"
Connecting ...
Connected to "woo"
Connected as SYSDBA.
New primary database "woo" is opening...
Operation requires start up of instance "woo" on database "woostd"
Starting instance "woo"...
Connected to an idle instance.
ORACLE instance started.
Connected to "WOOSTD"
Database mounted.
Database opened.
Connected to "WOOSTD"
Switchover succeeded, new primary is "woo"
DGMGRL> 
DGMGRL> 
DGMGRL>  show configuration;Configuration - woo_broker_cfgProtection Mode: MaxPerformanceMembers:woo    - Primary databasewoostd - Physical standby database Fast-Start Failover:  DisabledConfiguration Status:
SUCCESS   (status updated 62 seconds ago)DGMGRL> 
http://www.dtcms.com/a/569002.html

相关文章:

  • PsLoggedOn(7.17):谁在登录?多会话取证与审计
  • 深圳网站美化美容培训东莞网站建设
  • 网站开发流程主要分成什么wordpress 文艺小清新
  • 【Java8新特性】Stream 流深度实战:创建 /filter/map/collect 常用操作 + 惰性求值原理解析 + 并行安全避坑
  • 【STM32】智能排队控制系统
  • AISaaS出海工具整理
  • 电商网站如何做精细化运营dw软件下载官方免费下载
  • 在线教程丨端侧TTS新SOTA!NeuTTS-Air基于0.5B模型实现3秒音频克隆
  • 测试开发话题10---自动化测试常用函数(2)
  • Auto CAD二次开发——镜像图形对象
  • 软考 关于23种设计模式
  • golang 网站开发 教程网站建设公司如何规避风险
  • 建设电子商务网站论文网站开发核心技术
  • nestjs集成grpc服务
  • Milvus:标量索引详解(十三)
  • 【仓颉纪元】仓颉学习深度实践:30 天从零基础到独立开发
  • RocketMQ【入门实践】
  • Harmony鸿蒙开发0基础入门到精通Day11--TypeScript篇
  • 网站做广告的好处软件定制开发平台
  • 从智能手表拆解看硬件与软件的魔法融合 -嵌入式开发
  • 【java基础语法】---- 综合训练
  • BKA-Transformer-LSTM多变量时间序列预测Matlab实现
  • 如何自己创造一个网站平台搬瓦工装WordPress
  • 数式Oinone亮相GOTC 2025开源集市,企业级产品化引擎冲击Gitee当日热门项目
  • 【产品研究】生物力学软件 SIMM 4.0 for Windows 用户手册总结
  • 更新公司网站内容需要山东住房和城乡建设局网站首页
  • Unity与Android原生交互开发入门篇 - 打开Android的设置
  • 如何查看Linux系统版本?
  • Python类和对象--生命周期方法(对象生命周期,内存管理机制-存储,垃圾回收)
  • PAIMON+STARROCKS 学习