【構築】Oracle Data Guard (12.2)

【構築】Oracle Data Guard (12.2)
===============================

Oracle Databaseのdockerコンテナを使用して、Oracle Data Guardの構築手順、操作を調べる。

環境
----

Ubuntu上でsnapモジュールのdockerを使用しています。

```sh
$ grep VERSION= /etc/os-release 
VERSION="20.04.3 LTS (Focal Fossa)"

$ uname -a
Linux bionic 5.4.0-89-generic #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

$ snap list docker
Name    Version  Rev   Tracking       Publisher   Notes
docker  20.10.8  1125  latest/stable  canonical✓  -
```

準備
----

### Oracle Databaseのdockerイメージ作成

```sh
# Oracle dockerイメージ作成用のgitリポジトリをクローン
$ git clone https://github.com/oracle/docker-images.git

# Oracle Databaseのイメージ作成用ディレクトリに移動
$ cd ./oracle-docker-images/OracleDatabase/SingleInstance/dockerfiles

# Oracleインストールイメージを配置
mv linuxx64_12201_database.zip ./12.2.0.1

# dockerイメージ作成
./buildContainerImage.sh -v 12.2.0.1 -t oracle/database:12.2.0.1-ee -e
```

### dockerコンテナ作成

以下の2つのOracle Databaseコンテナを作成する。

ホスト名 | SID     | 説明
--------|---------|------
db1     | ORACDB1 | プライマリデータベース
db2     | ORACDB2 | スタンバイデータベース

コンテナ作成はdocker composeを使用する。

```yml:docker-compose.yml
version: '3.5'
services:
  db1:
    image: oracle/database:12.2.0.1-ee
    hostname: db1
    ports:
      - "11521:1521"
      - "15500:5500"
      - "18080:8080"
    volumes:
      - "./db1/opt/oracle/oradata/:/opt/oracle/oradata/:rw"
      - "./db1/opt/oracle/fast_recovery_area/:/opt/oracle/fast_recovery_area/:rw"
    environment:
      - ORACLE_SID=ORACDB1
      - ORACLE_PDB=ORAPDB
      - ORACLE_PWD=P%ssw0rd
      - ORACLE_CHARACTERSET=AL32UTF8
      - ENABLE_ARCHIVELOG=true
  db2:
    image: oracle/database:12.2.0.1-ee
    hostname: db2
    ports:
      - "21521:1521"
      - "25500:5500"
      - "28080:8080"
    volumes:
      - "./db2/opt/oracle/oradata/:/opt/oracle/oradata/:rw"
      - "./db2/opt/oracle/fast_recovery_area/:/opt/oracle/fast_recovery_area/:rw"
    environment:
      - ORACLE_SID=ORACDB2
      - ORACLE_PDB=ORAPDB
      - ORACLE_PWD=P%ssw0rd
      - ORACLE_CHARACTERSET=AL32UTF8
      - ENABLE_ARCHIVELOG=true
```

コンテナのoracleユーザが永続化用のデータ格納ディレクトリにアクセスできるように、事前にディレクトリを作成してパーミッションを設定する。

```sh
$ mkdir -p ./db{1,2}/opt/oracle/{fast_recovery_area,oradata}
$ chmod a+w ./db{1,2}/opt/oracle/{fast_recovery_area,oradata}
```

dockerコンテナ作成
※使用環境ではdocker-composeは `docker.compose` コマンドで使用する。

```sh
# コンテナ作成（初回実行時にデータベース構築するため時間がかかる）
$ docker.compose up -d

# コンテナ確認
$ docker.compose ps
```
```txt:結果
        Name                       Command                  State                                        Ports                                  
------------------------------------------------------------------------------------------------------------------------------------------------
study-oracle12c_db1_1   /bin/sh -c exec $ORACLE_BA ...   Up (healthy)   0.0.0.0:11521->1521/tcp,:::11521->1521/tcp,                             
                                                                        0.0.0.0:15500->5500/tcp,:::15500->5500/tcp,                             
                                                                        0.0.0.0:18080->8080/tcp,:::18080->8080/tcp                              
study-oracle12c_db2_1   /bin/sh -c exec $ORACLE_BA ...   Up (healthy)   0.0.0.0:21521->1521/tcp,:::21521->1521/tcp,                             
                                                                        0.0.0.0:25500->5500/tcp,:::25500->5500/tcp,                             
                                                                        0.0.0.0:28080->8080/tcp,:::28080->8080/tcp  
```

Oracleネットワーク設定
--------------------

### リスナー設定

コンテナ内でではエディタが使用できないため、ホスト側でlistener.oraファイルを以下の通り編集する。

```scheme:db1/opt/oracle/oradata/dbconfig/ORACDB1/listener.ora
LISTENER =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = ORACDB1)
      (ORACLE_HOME = /opt/oracle/product/12.2.0.1/dbhome_1)
    )
  )

DEDICATED_THROUGH_BROKER_LISTENER=ON
DIAG_ADR_ENABLED = off
```
```scheme:db2/opt/oracle/oradata/dbconfig/ORACDB2/listener.ora
LISTENER =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = ORACDB2)
      (ORACLE_HOME = /opt/oracle/product/12.2.0.1/dbhome_1)
    )
  )

DEDICATED_THROUGH_BROKER_LISTENER=ON
DIAG_ADR_ENABLED = off
```

設定変更をコンテナのリスナーに反映する。
※以下の操作はdb1のみ。db2についても同様に操作する。

```sh
# コンテナに接続
$ docker.compose exec db1 /bin/bash

# リスナー再起動
$ lsnrctl stop
$ lsnrctl start

# 確認
$ lsnrctl status
```
```txt:結果
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 21-OCT-2021 12:47:24

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=0.0.0.0)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                21-OCT-2021 12:34:34
Uptime                    0 days 0 hr. 12 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/12.2.0.1/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/db1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=db1)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/ORACDB1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "ORACDB1" has 2 instance(s).
  Instance "ORACDB1", status UNKNOWN, has 1 handler(s) for this service...
  Instance "ORACDB1", status READY, has 1 handler(s) for this service...
Service "ORACDB1XDB" has 1 instance(s).
  Instance "ORACDB1", status READY, has 1 handler(s) for this service...
Service "ced9b8a51ed10967e053030019ac921f" has 1 instance(s).
  Instance "ORACDB1", status READY, has 1 handler(s) for this service...
Service "orapdb" has 1 instance(s).
  Instance "ORACDB1", status READY, has 1 handler(s) for this service...
The command completed successfully
```

### ネットサービス名設定

db1、db2ともにファイル内容は同じ。

```scheme:db1/opt/oracle/oradata/dbconfig/ORACDB1/tnsnames.ora
ORACDB1=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORACDB1)
      (UR = A)
    )
  )

ORACDB2=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORACDB2)
      (UR = A)
    )
  )
```
```scheme:db2/opt/oracle/oradata/dbconfig/ORACDB2/tnsnames.ora
ORACDB1=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORACDB1)
      (UR = A)
    )
  )

ORACDB2=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORACDB2)
      (UR = A)
    )
  )
```

フィジカル・スタンバイ・データベースの作成
-------------------------------------

### スタンバイ・データベースを作成するためのプライマリ・データベースの準備

```sh:データベースに接続
$ docker.compose exec db1 /bin/bash
$ sqlplus / as sysdba
```

```sql:強制ロギングの有効化
ALTER DATABASE FORCE LOGGING;
```

```sql:アーカイブの有効化
SHUTDOWN IMMEDIATE
STARTUP MOUNT
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
```

```sql:確認
set lines 140
set pages 999
SELECT database_role,open_mode,log_mode,force_logging FROM v$database;
```
```txt:結果
DATABASE_ROLE    OPEN_MODE            LOG_MODE     FORCE_LOGGING
---------------- -------------------- ------------ ---------------------------------------
PRIMARY          READ WRITE           ARCHIVELOG   YES
```

### REDOデータを受信するためのプライマリ・データベースの構成

```sql:REDOログファイル確認
set lines 140
set pages 999
col member format A60
col IS_RECOVERY_DEST_FILE format A22
col CON_ID format 99
SELECT * FROM gv$logfile ORDER BY GROUP#;
```
```
   INST_ID     GROUP# STATUS  TYPE    MEMBER                                                       IS_RECOVERY_DEST_FILE  CON_ID
---------- ---------- ------- ------- ------------------------------------------------------------ ---------------------- ------
         1          1         ONLINE  /opt/oracle/oradata/ORACDB1/redo01.log                       NO                          0
         1          2         ONLINE  /opt/oracle/oradata/ORACDB1/redo02.log                       NO                          0
         1          3         ONLINE  /opt/oracle/oradata/ORACDB1/redo03.log                       NO                          0
```
```sql:REDOログファイル確認（サイズ）
SELECT group#,bytes/1048576 "SIZE(MB)" FROM v$log;
```
```
    GROUP#   SIZE(MB)
---------- ----------
         1        200
         2        200
         3        200
```

```sql:スタンバイREDOログファイルの作成
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1
  GROUP 4 ('/opt/oracle/oradata/ORACDB1/redo01_standby.log') SIZE 200M,
  GROUP 5 ('/opt/oracle/oradata/ORACDB1/redo02_standby.log') SIZE 200M,
  GROUP 6 ('/opt/oracle/oradata/ORACDB1/redo03_standby.log') SIZE 200M,
  GROUP 7 ('/opt/oracle/oradata/ORACDB1/redo04_standby.log') SIZE 200M;
```
```sql:結果確認
SELECT * FROM gv$logfile ORDER BY GROUP#;
```
```
   INST_ID     GROUP# STATUS  TYPE    MEMBER                                                       IS_RECOVERY_DEST_FILE  CON_ID
---------- ---------- ------- ------- ------------------------------------------------------------ ---------------------- ------
         1          1         ONLINE  /opt/oracle/oradata/ORACDB1/redo01.log                       NO                          0
         1          2         ONLINE  /opt/oracle/oradata/ORACDB1/redo02.log                       NO                          0
         1          3         ONLINE  /opt/oracle/oradata/ORACDB1/redo03.log                       NO                          0
         1          4         STANDBY /opt/oracle/oradata/ORACDB1/redo01_standby.log               NO                          0
         1          5         STANDBY /opt/oracle/oradata/ORACDB1/redo02_standby.log               NO                          0
         1          6         STANDBY /opt/oracle/oradata/ORACDB1/redo03_standby.log               NO                          0
         1          7         STANDBY /opt/oracle/oradata/ORACDB1/redo04_standby.log               NO                          0
```

### プライマリ・データベースの初期化パラメータの設定

```sql:初期化パラメータ設定
ALTER SYSTEM SET 
ALTER SYSTEM SET db_recovery_file_dest='/opt/oracle/fast_recovery_area' SCOPE=SPFILE;
ALTER SYSTEM SET db_recovery_file_dest_size=2G SCOPE=SPFILE;
ALTER SYSTEM SET log_archive_config='DG_CONFIG=(ORACDB1,ORACDB2)' SCOPE=SPFILE;
ALTER SYSTEM SET log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORACDB1' SCOPE=SPFILE;
ALTER SYSTEM SET log_archive_dest_2='SERVICE=ORACDB2 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORACDB2' SCOPE=SPFILE;
ALTER SYSTEM SET fal_server='ORACDB2' SCOPE=SPFILE;
```
```sql:初期化パラメータファイル作成
CREATE PFILE='/opt/oracle/oradata/dbconfig/ORACDB1/initORACDB1.ora' FROM SPFILE;
```

### スタンバイ・データベース用のインスタンス設定

```sh:初期化パラメータファイルをコピー
$ cp db1/opt/oracle/oradata/dbconfig/ORACDB1/initORACDB1.ora \
     db2/opt/oracle/oradata/dbconfig/ORACDB2/initORACDB2.ora
```
```diff:初期化パラメータをORACDB2用に編集
--- db1/opt/oracle/oradata/dbconfig/ORACDB1/initORACDB1.ora     2021-10-21 22:53:12.657628758 +0900
+++ db2/opt/oracle/oradata/dbconfig/ORACDB2/initORACDB2.ora     2021-10-21 22:54:23.909219368 +0900
@@ -1,32 +1,32 @@
-ORACDB1.__data_transfer_cache_size=0
-ORACDB1.__db_cache_size=1124073472
-ORACDB1.__inmemory_ext_roarea=0
-ORACDB1.__inmemory_ext_rwarea=0
-ORACDB1.__java_pool_size=16777216
-ORACDB1.__large_pool_size=33554432
-ORACDB1.__oracle_base='/opt/oracle'#ORACLE_BASE set from environment
-ORACDB1.__pga_aggregate_target=536870912
-ORACDB1.__sga_target=1610612736
-ORACDB1.__shared_io_pool_size=83886080
-ORACDB1.__shared_pool_size=335544320
-ORACDB1.__streams_pool_size=0
-*.audit_file_dest='/opt/oracle/admin/ORACDB1/adump'
+ORACDB2.__data_transfer_cache_size=0
+ORACDB2.__db_cache_size=1124073472
+ORACDB2.__inmemory_ext_roarea=0
+ORACDB2.__inmemory_ext_rwarea=0
+ORACDB2.__java_pool_size=16777216
+ORACDB2.__large_pool_size=33554432
+ORACDB2.__oracle_base='/opt/oracle'#ORACLE_BASE set from environment
+ORACDB2.__pga_aggregate_target=536870912
+ORACDB2.__sga_target=1610612736
+ORACDB2.__shared_io_pool_size=83886080
+ORACDB2.__shared_pool_size=335544320
+ORACDB2.__streams_pool_size=0
+*.audit_file_dest='/opt/oracle/admin/ORACDB2/adump'
 *.audit_sys_operations=false
 *.audit_trail='none'
 *.compatible='12.2.0'
-*.control_files='/opt/oracle/oradata/ORACDB1/control01.ctl'
+*.control_files='/opt/oracle/oradata/ORACDB2/control01.ctl'
 *.db_block_size=8192
-*.db_name='ORACDB1'
+*.db_name='ORACDB2'
 *.db_recovery_file_dest='/opt/oracle/fast_recovery_area'
 *.db_recovery_file_dest_size=2147483648
-*.db_unique_name='ORACDB1'
+*.db_unique_name='ORACDB2'
 *.diagnostic_dest='/opt/oracle'
-*.dispatchers='(PROTOCOL=TCP) (SERVICE=ORACDB1XDB)'
+*.dispatchers='(PROTOCOL=TCP) (SERVICE=ORACDB2XDB)'
 *.enable_pluggable_database=true
-*.fal_server='ORACDB2'
-*.log_archive_config='DG_CONFIG=(ORACDB1,ORACDB2)'
-*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORACDB1'
-*.log_archive_dest_2='SERVICE=ORACDB2 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORACDB2'
+*.fal_server='ORACDB1'
+*.log_archive_config='DG_CONFIG=(ORACDB2,ORACDB1)'
+*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORACDB2'
+*.log_archive_dest_2='SERVICE=ORACDB1 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORACDB1'
 *.nls_language='AMERICAN'
 *.nls_territory='AMERICA'
 *.open_cursors=300
```

```sh:データベースに接続
$ docker.compose exec db2 /bin/bash
$ sqlplus / as sysdba
```
```sql:スタンバイ・データベース用にインスタンスを再起動
shutdown immediate
startup nomount pfile='/opt/oracle/oradata/dbconfig/ORACDB2/initORACDB2.ora'
```

### フィジカル・スタンバイ・データベース作成

```sh:RMAN接続
$ rman target sys/P%ssw0rd@ORACDB1 auxiliary sys/P%ssw0rd@ORACDB2
Recovery Manager: Release 12.2.0.1.0 - Production on Thu Oct 21 14:16:10 2021

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

connected to target database: ORACDB1 (DBID=1164041823)
connected to auxiliary database: ORACDB2 (not mounted)
```
```sql:スタンバイ・データベース複製
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER
  SPFILE
    SET DB_UNIQUE_NAME='ORACDB2'
    SET AUDIT_FILE_DEST='/opt/oracle/admin/ORACDB2/adump'
    SET CONTROL_FILES='/opt/oracle/oradata/ORACDB2/control01.ctl'
    SET DB_FILE_NAME_CONVERT='/ORACDB1/','/ORACDB2/'
    SET LOG_FILE_NAME_CONVERT='/ORACDB1/','/ORACDB2/'
    SET LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORACDB2'
    SET LOG_ARCHIVE_DEST_2='SERVICE=ORACDB1 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORACDB1'
    SET FAL_SERVER='ORACDB1';
```
```txt:結果
Starting Duplicate Db at 21-OCT-21
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=261 device type=DISK
current log archived

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/opt/oracle/product/12.2.0.1/dbhome_1/dbs/orapwORACDB1' auxiliary format 
 '/opt/oracle/product/12.2.0.1/dbhome_1/dbs/orapwORACDB2'   ;
   restore clone from service  'ORACDB1' spfile to 
 '/opt/oracle/product/12.2.0.1/dbhome_1/dbs/spfileORACDB2.ora';
   sql clone "alter system set spfile= ''/opt/oracle/product/12.2.0.1/dbhome_1/dbs/spfileORACDB2.ora''";
}
executing Memory Script

Starting backup at 21-OCT-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=392 device type=DISK
Finished backup at 21-OCT-21

〜省略〜

Starting recover at 21-OCT-21
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 3 is already on disk as file /opt/oracle/fast_recovery_area/ORACDB2/archivelog/2021_10_21/o1_mf_1_3_jq2xqd0l_.arc
archived log for thread 1 with sequence 4 is already on disk as file /opt/oracle/fast_recovery_area/ORACDB2/archivelog/2021_10_21/o1_mf_1_4_jq2xqf12_.arc
archived log file name=/opt/oracle/fast_recovery_area/ORACDB2/archivelog/2021_10_21/o1_mf_1_3_jq2xqd0l_.arc thread=1 sequence=3
archived log file name=/opt/oracle/fast_recovery_area/ORACDB2/archivelog/2021_10_21/o1_mf_1_4_jq2xqf12_.arc thread=1 sequence=4
media recovery complete, elapsed time: 00:00:01
Finished recover at 21-OCT-21
Finished Duplicate Db at 21-OCT-21
```

データベース複製により、スタンバイ・データベースのspfileがコンテナ内のディレクトリに作成されるため、永続化ディレクトリに移動してシンボリックリンクを作り直す。

```sh:
$ cd $ORACLE_HOME/dbs
$ mv spfileORACDB2.ora /opt/oracle/oradata/dbconfig/ORACDB2/spfileORACDB2.ora 
$ ln -s /opt/oracle/oradata/dbconfig/ORACDB2/spfileORACDB2.ora .
```

スタンバイ・データベースの状態確認

```sh:データベースに接続
$ docker.compose exec db2 /bin/bash
$ sqlplus / as sysdba
```
```sql:モード確認
set lines 140
set pages 999
SELECT database_role,open_mode,log_mode,force_logging FROM v$database;
```
```txt:結果
DATABASE_ROLE    OPEN_MODE            LOG_MODE     FORCE_LOGGING
---------------- -------------------- ------------ ---------------------------------------
PHYSICAL STANDBY MOUNTED              ARCHIVELOG   YES
```

プライマリ・データベース再起動

```sh:データベースに接続
$ docker.compose exec db1 /bin/bash
$ sqlplus / as sysdba
```
```sql:インスタンス再起動
SHUTDOWN IMMEDIATE
STARTUP
```
```sql:モード確認
set lines 140
set pages 999
SELECT database_role,open_mode,log_mode,force_logging FROM v$database;
```
```txt:結果
DATABASE_ROLE    OPEN_MODE            LOG_MODE     FORCE_LOGGING
---------------- -------------------- ------------ ---------------------------------------
PRIMARY          READ WRITE           ARCHIVELOG   YES
```

Data Guard Broker設定
---------------------

### Data Guard Broker起動

```sh:ORACDB1
$ docker.compose exec db1 /bin/bash
$ sqlplus -S / as sysdba <<'SQL'
ALTER SYSTEM SET DG_BROKER_START=TRUE;
SQL
```
```sh:ORACDB2
$ docker.compose exec db2 /bin/bash
$ sqlplus -S / as sysdba <<'SQL'
ALTER SYSTEM SET DG_BROKER_START=TRUE;
SQL
```

### Data Guard Broker構成

```sh:DGMGRL接続
$ docker.compose exec db1 /bin/bash
$ dgmgrl /
```
```
DGMGRL for Linux: Release 12.2.0.1.0 - Production on Thu Oct 21 14:47:08 2021

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

Welcome to DGMGRL, type "help" for information.
Connected to "ORACDB1"
Connected as SYSDG.
```
```sql:プライマリDBを登録
DGMGRL> CREATE CONFIGURATION DGCONFIG AS PRIMARY DATABASE IS ORACDB1 CONNECT IDENTIFIER IS ORACDB1;
Configuration "dgconfig" created with primary database "oracdb1"
```
```sql:スタンバイDBを登録
DGMGRL> ADD DATABASE ORACDB2 AS CONNECT IDENTIFIER IS ORACDB2 MAINTAINED AS PHYSICAL;
Database "oracdb2" added
```
```sql:ブローカ構成を有効化
DGMGRL> enable configuration
Enabled.
```
```sql:ブローカ構成の状態確認
DGMGRL> show configuration

Configuration - dgconfig

  Protection Mode: MaxPerformance
  Members:
  oracdb1 - Primary database
    oracdb2 - Physical standby database 

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS   (status updated 25 seconds ago)
```
```sql:プライマリDB状態確認
DGMGRL> show database ORACDB1

Database - oracdb1

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

Database Status:
SUCCESS
```
```sql:スタンバイDB状態確認
DGMGRL> show database ORACDB2

Database - oracdb2

  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: 8.00 KByte/s
  Real Time Query:    OFF
  Instance(s):
    ORACDB2

Database Status:
SUCCESS
```

参考
----

- [Oracle Data Guard概要および管理, 12cリリース2 (12.2)](https://docs.oracle.com/cd/E82638_01/sbydb/index.html)
- [Oracle Data Guard Broker, 12cリリース2 (12.2)](https://docs.oracle.com/cd/E82638_01/dgbkr/index.html)
- [Oracle DataGuard - Qiita](https://qiita.com/fururun02/items/fc4a95dd844949cdfdb7)