Configure Oracle 19c DataGuard Step By Step Guide

本文包含如下兩個知識點,環境信息以下圖所示:sql

  1. 部署Data Guard服務;
  2. Data Guard Broker的配置以及使用。
    Configure Oracle 19c DataGuard Step By Step Guide

    1、部署Physical Standby

    1.1 主庫準備工做

    1.1.1啓用force logging

    SQL> ALTER DATABASE FORCE LOGGING;

    1.1.2 建立standby數據庫redo文件

    SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M;
    SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M;
    SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M;
    SQL> ALTER DATABASE ADD STANDBY LOGFILE SIZE 200M;

    Configure Oracle 19c DataGuard Step By Step Guide

    1.1.3 設置主庫參數

    SQL> alter system set log_archive_config='dg_config=(cdb,cdb_stby)' scope=both;
    SQL> alter system set log_archive_dest_2='service=cdb_stby async valid_for=(online_logfile,primary_role) db_unique_name=cdb_stby';
    SQL> alter system set standby_file_management=auto;

    1.1.4 確保主庫處於歸檔模式

    Configure Oracle 19c DataGuard Step By Step Guide

1.1.5 編輯tnsnames.ora

[oracle@db03 admin]$ vi tnsnames.ora 
CDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.83)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdb)
    )
  )

CDB_STBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.82)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdb)
      (UR=A)
    )
  )

1.1.6 配置靜態監聽地址

編輯listener.ora文件,加入下面的內容:數據庫

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = cdb)
      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1)
      (SID_NAME = cdb)
    )
   (SID_DESC =
      (GLOBAL_DBNAME = cdb_stby)
      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1)
      (SID_NAME = cdb)
    )
)

切記,必須重啓監聽方可生效。oracle

1.2 備庫準備工做

1.2.1 建立備庫密碼文件

直接複製主庫的密碼文件到備庫相應目錄。app

[oracle@db03 dbs]$ scp orapwcdb db02:$ORACLE_HOME/dbs/

1.2.2 建立初始化文件

[oracle@db02 ~]$ cd $ORACLE_HOME/dbs
[oracle@db02 dbs]$ echo DB_NAME=cdb>initcdb.ora

1.2.3 建立adump目錄

[oracle@db02 ~]$ mkdir -p $ORACLE_BASE/admin/cdb/adump

1.2.4 配置靜態監聽地址

編輯listener.ora文件,加入下面的內容:async

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = cdb)
      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1)
      (SID_NAME = cdb)
    )
   (SID_DESC =
      (GLOBAL_DBNAME = cdb_stby)
      (ORACLE_HOME = /u01/app/oracle/product/19.0.0/db_1)
      (SID_NAME = cdb)
    )
)

切記,必須重啓監聽方可生效。ide

1.2.5 啓動備庫至nomount

[oracle@db02 ~]$ sqlplus "/as sysdba"
SQL> startup nomount

1.2.6 編輯tnsnames.ora

[oracle@db02 admin]$ vi tnsnames.ora 
CDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.83)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdb)
    )
  )

CDB_STBY =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.120.82)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdb)
      (UR=A)
    )
  )

1.3 建立physical standby database與驗證

1.3.1 建立備庫

這裏直接使用duplicate方式在線建立備庫,在rman中運行下面的腳本:ui

[oracle@db03 ~]$ rman target / auxiliary sys/abcABC12@cdb_stby  
run {
        allocate channel prmy1 type disk;
        allocate channel prmy2 type disk;
        allocate channel prmy3 type disk;
        allocate channel prmy4 type disk;
        allocate auxiliary channel stby type disk;
        duplicate target database for standby from active database
        spfile
                set db_unique_name='cdb_stby'
                set fal_client='cdb_stby'
                set fal_server='cdb'
                set standby_file_management='AUTO'
                set log_file_name_convert='/cdb/','/cdb_stby/'
                set db_file_name_convert='/cdb/','/cdb_stby/'
                set log_archive_config='dg_config=(cdb,cdb_stby)'
                set log_archive_dest_2='service=cdb ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=cdb';
}

腳本成功執行後,使用下面的SQL驗證備庫的狀態:rest

SQL> select status,instance_name from v$instance;

1.3.2 啓用redo日誌應用

在主庫節點先執行日誌切換操做,而後在備庫上啓用redo日誌應用。日誌

SQL> alter database recover managed standby database using current logfile disconnect;

1.3.3 主備庫角色驗證

分別在主備庫上,執行下面的SQL進行驗證:code

--主庫
SQL> select database_role,switchover_status from v$database;

Configure Oracle 19c DataGuard Step By Step Guide

--備庫
SQL> select database_role,switchover_status from v$database;

Configure Oracle 19c DataGuard Step By Step Guide

2、配置DG Broker服務

2.1 主備庫啓用broker

主備庫上執行下面的SQL啓用broker:

SQL> ALTER SYSTEM SET dg_broker_start=true scope=both;

2.2 建立broker配置文件

執行下面的命令鏈接主庫並建立配置文件:

[oracle@db03 ~]$ dgmgrl sys@cdb as sysdba
DGMGRL for Linux: Release 19.0.0.0.0 - Production on Tue May 7 16:22:12 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Password:
Connected to "cdb"
Connected as SYSDBA.
DGMGRL> create configuration dg_cfg as primary database is cdb connect identifier is cdb;
Configuration "dg_cfg" created with primary database "cdb"
DGMGRL> add database cdb_stby as connect identifier is cdb_stby maintained as physical;
Database "cdb_stby" added
DGMGRL> enable configuration;
enabled.
DGMGRL>

若是添加standby數據庫的時候,報以下錯誤:

ORA-16698: LOG_ARCHIVE_DEST_n parameter set for object to be added

在備庫上,將LOG_ARCHIVE_DEST_2參數的值清空從新添加便可。

SQL> alter system set LOG_ARCHIVE_DEST_2=' ' scope=both;

2.3 查看配置文件信息

DGMGRL> show configuration;

Configuration - dg_cfg

  Protection Mode: MaxPerformance
  Members:
  cdb      - Primary database
    cdb_stby - Physical standby database 

Fast-Start Failover:  Disabled

Configuration Status:
SUCCESS   (status updated 17 seconds ago)

DGMGRL> show database cdb;

Database - cdb

  Role:               PRIMARY
  Intended State:     TRANSPORT-ON
  Instance(s):
    cdb

Database Status:
SUCCESS

DGMGRL> show database cdb_stby;

Database - cdb_stby

  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: 2.00 KByte/s
  Real Time Query:    ON
  Instance(s):
    cdb

Database Status:
SUCCESS

2.4 使用dgmgrl執行主備切換

DGMGRL> show configuration;

Configuration - dg_cfg

  Protection Mode: MaxPerformance
  Members:
  cdb      - Primary database
    cdb_stby - Physical standby database 

Fast-Start Failover:  Disabled

Configuration Status:
SUCCESS   (status updated 26 seconds ago)

DGMGRL> switchover to cdb_stby;
Performing switchover NOW, please wait...
Operation requires a connection to database "cdb_stby"
Connecting ...
Connected to "cdb_stby"
Connected as SYSDBA.
New primary database "cdb_stby" is opening...
Oracle Clusterware is restarting database "cdb" ...
Connected to an idle instance.
Connected to an idle instance.
Connected to an idle instance.
Connected to an idle instance.
Connected to an idle instance.
Connected to "cdb"
Connected to "cdb"
Switchover succeeded, new primary is "cdb_stby"
DGMGRL> show configuration;

Configuration - dg_cfg

  Protection Mode: MaxPerformance
  Members:
  cdb_stby - Primary database
    cdb      - Physical standby database 

Fast-Start Failover:  Disabled

Configuration Status:
SUCCESS   (status updated 15 second ago)
相關文章
相關標籤/搜索