top of page

Building a Data Guard Physical Standby with the Broker in Oracle Database 23ai — Runbook

OmerNarman
Oct 10
6 min read

Updated: Oct 24

Environment used in this runbook:

  • Primary: CDB CDB23 with DB_UNIQUE_NAME = cdb23_a on host dbhost-a

  • Standby: DB_UNIQUE_NAME = cdb23_b on host dbhost-b

  • Software: same 23ai home and Release Update on both hosts

  • Platform: Linux x86-64, file-system storage under /u02/oradata

  • Licensing: Data Guard is included in Enterprise Edition; opening the standby read-only with redo apply running (Active Data Guard) is a separately licensed option on-premises


Design in one paragraph

Redo from the primary is shipped by the log writer to standby redo logs on the standby, where managed recovery applies it continuously (real-time apply). The Data Guard Broker owns the configuration: it sets the transport/apply parameters, monitors health, and executes switchover and failover with single commands. In 23ai every database is a CDB, so the whole CDB (all PDBs) is protected as one unit.

Phase 1 — Prepare the primary (no downtime)

Step 1.1 — Archiving, force logging, flashback

SQL

SELECT log_mode, force_logging, flashback_on FROM v$database;

-- if needed (ARCHIVELOG requires a mount-state restart):

-- SHUTDOWN IMMEDIATE; STARTUP MOUNT; ALTER DATABASE ARCHIVELOG; ALTER DATABASE OPEN;

ALTER DATABASE FORCE LOGGING;

ALTER DATABASE FLASHBACK ON; -- lets a failed-over primary be reinstated later

Why: FORCE LOGGING guarantees that NOLOGGING operations are still shipped, otherwise the standby silently gets corrupt blocks. Flashback on the primary enables REINSTATE after a failover.

Step 1.2 — Standby redo logs on the primary

SQL

SELECT group#, thread#, bytes/1024/1024 AS mb FROM v$log;

-- one more SRL group than online redo groups, same size, per thread

ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 11 SIZE 1G;

ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 12 SIZE 1G;

ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 13 SIZE 1G;

ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 14 SIZE 1G;

Why: the primary needs SRLs for the day it becomes the standby after a switchover; RMAN duplicate copies the layout to the standby.

Step 1.3 — Parameters

SQL

ALTER SYSTEM SET db_unique_name = 'cdb23_a' SCOPE = SPFILE; -- if not already set (needs restart)

ALTER SYSTEM SET log_archive_config = 'DG_CONFIG=(cdb23_a,cdb23_b)' SCOPE = BOTH;

ALTER SYSTEM SET standby_file_management = 'AUTO' SCOPE = BOTH;

ALTER SYSTEM SET dg_broker_start = TRUE SCOPE = BOTH;

ALTER SYSTEM SET db_recovery_file_dest_size = 200G SCOPE = BOTH;

ALTER SYSTEM SET db_recovery_file_dest = '/u02/fra' SCOPE = BOTH;

Why: the broker will set LOG_ARCHIVE_DEST_2, FAL_SERVER and friends itself — do not configure them manually when using the broker. STANDBY_FILE_MANAGEMENT = AUTO makes new datafiles appear on the standby automatically.

Step 1.4 — Network: TNS aliases and static listener entries on both hosts

tnsnames.ora (identical on both hosts):

SQL

cdb23_a = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-a)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=cdb23_a)))

cdb23_b = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-b)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=cdb23_b)))

listener.ora on dbhost-b (the same pattern with cdb23_a on dbhost-a):

SQL

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC = (GLOBAL_DBNAME = cdb23_b) (ORACLE_HOME = /u01/app/oracle/product/23.0.0/dbhome_1) (SID_NAME = CDB23))

(SID_DESC = (GLOBAL_DBNAME = cdb23_b_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/23.0.0/dbhome_1) (SID_NAME = CDB23)))

Shell

lsnrctl reload

Why: RMAN duplicate must reach a NOMOUNT instance that has not registered itself yet, and the broker restarts instances during switchover through the <db_unique_name>_DGMGRL static service. Without these entries both steps fail with ORA-12514.

Step 1.5 — Copy the password file and the TDE keystore

Shell

# on dbhost-a

scp $ORACLE_HOME/dbs/orapwCDB23 oracle@dbhost-b:$ORACLE_HOME/dbs/orapwCDB23

# TDE (if enabled): keystore must be identical on the standby

scp -r /u01/app/oracle/admin/CDB23/wallet oracle@dbhost-b:/u01/app/oracle/admin/CDB23/

Why: redo transport authenticates with SYS/SYSDG through the password file; the standby cannot apply redo for encrypted tablespaces without the same master key. Repeat the wallet copy after every key rotation.

Phase 2 — Prepare the standby host

Shell

# dbhost-b, as oracle

mkdir -p /u01/app/oracle/admin/CDB23/adump /u02/oradata/CDB23 /u02/fra

cat > $ORACLE_HOME/dbs/initCDB23.ora <<EOF

db_name=CDB23

db_unique_name=cdb23_b

enable_pluggable_database=TRUE

EOF

export ORACLE_SID=CDB23

sqlplus / as sysdba <<EOF

STARTUP NOMOUNT PFILE='$ORACLE_HOME/dbs/initCDB23.ora';

EOF

Why: a three-line pfile is enough — DUPLICATE ... SPFILE copies the primary's SPFILE and rewrites the values you list.

Verify connectivity from dbhost-a:

Shell

sqlplus sys@cdb23_b as sysdba # must connect to the idle/NOMOUNT instance

Phase 3 — Create the standby with RMAN

RMAN

# on dbhost-a

rman TARGET sys@cdb23_a AUXILIARY sys@cdb23_b

RUN {

ALLOCATE CHANNEL p1 DEVICE TYPE DISK;

ALLOCATE CHANNEL p2 DEVICE TYPE DISK;

ALLOCATE AUXILIARY CHANNEL s1 DEVICE TYPE DISK;

ALLOCATE AUXILIARY CHANNEL s2 DEVICE TYPE DISK;

DUPLICATE TARGET DATABASE

FOR STANDBY

FROM ACTIVE DATABASE

DORECOVER

SPFILE

SET db_unique_name = 'cdb23_b'

SET log_archive_config = 'DG_CONFIG=(cdb23_a,cdb23_b)'

SET db_recovery_file_dest = '/u02/fra'

SET audit_file_dest = '/u01/app/oracle/admin/CDB23/adump'

SET dg_broker_start = 'TRUE'

SET db_file_name_convert '/u02/oradata/CDB23_A','/u02/oradata/CDB23'

SET log_file_name_convert '/u02/oradata/CDB23_A','/u02/oradata/CDB23'

RESET log_archive_dest_2

RESET fal_server

NOFILENAMECHECK;

}

Why: FROM ACTIVE DATABASE streams the datafiles over the network — no backup staging. FOR STANDBY creates a standby control file; DORECOVER applies the archived logs generated during the copy. RESET clears transport parameters the broker will manage. Drop the *_name_convert lines if directories are identical on both hosts (then NOFILENAMECHECK is what allows it).

Phase 4 — Broker configuration

DGMGRL

dgmgrl sys@cdb23_a

DGMGRL> CREATE CONFIGURATION dg_cdb23 AS PRIMARY DATABASE IS cdb23_a CONNECT IDENTIFIER IS cdb23_a;

DGMGRL> ADD DATABASE cdb23_b AS CONNECT IDENTIFIER IS cdb23_b MAINTAINED AS PHYSICAL;

DGMGRL> ENABLE CONFIGURATION;

DGMGRL> SHOW CONFIGURATION; -- wait ~1 min, then: SUCCESS

DGMGRL> SHOW DATABASE cdb23_b; -- Intended State: APPLY-ON, Transport Lag/Apply Lag: 0 seconds

DGMGRL> VALIDATE DATABASE cdb23_b; -- "Ready for Switchover: Yes"

Why: ENABLE CONFIGURATION is the moment the broker writes LOG_ARCHIVE_DEST_2 on the primary and starts managed recovery on the standby. Anything reported as a warning by SHOW/VALIDATE (missing SRLs, wrong StaticConnectIdentifier, flashback off) should be fixed now, not during the first switchover.

Step 4.1 — Choose the protection mode

DGMGRL

DGMGRL> EDIT DATABASE cdb23_a SET PROPERTY LogXptMode = 'SYNC';

DGMGRL> EDIT DATABASE cdb23_b SET PROPERTY LogXptMode = 'SYNC';

DGMGRL> EDIT CONFIGURATION SET PROTECTION MODE AS MaxAvailability;

Why: MaxPerformance (default, ASYNC) never slows the primary; MaxAvailability (SYNC) guarantees zero data loss as long as the standby is reachable. Set LogXptMode on both databases so the mode survives a switchover. FASTSYNC is a middle ground for higher latency links.

Step 4.2 — Optional: open the standby read-only (Active Data Guard)

SQL

-- on dbhost-b

ALTER DATABASE OPEN READ ONLY;

ALTER PLUGGABLE DATABASE ALL OPEN READ ONLY;

The broker keeps redo apply running; verify with SHOW DATABASE cdb23_b (Real Time Query: ON). Requires the Active Data Guard license on-premises.

Phase 5 — Test the role transitions (do this before go-live)

DGMGRL

DGMGRL> VALIDATE DATABASE cdb23_b;

DGMGRL> SWITCHOVER TO cdb23_b; -- planned: zero data loss, both databases keep running

DGMGRL> SHOW CONFIGURATION;

DGMGRL> SWITCHOVER TO cdb23_a; -- and back

Failover rehearsal (only in a test environment, it breaks the old primary):

DGMGRL

DGMGRL> FAILOVER TO cdb23_b;

DGMGRL> REINSTATE DATABASE cdb23_a; -- uses flashback on the old primary, then re-syncs it as standby

Why: a switchover that has never been exercised will not work at 3 a.m. Check that the application reconnects (use role-based services, next step).

Phase 6 — Role-based services for the application

SQL

-- on the primary, in the PDB

EXEC DBMS_SERVICE.CREATE_SERVICE(service_name => 'app_rw', network_name => 'app_rw');

-- start it only where the role is PRIMARY

CREATE OR REPLACE TRIGGER sys.trg_start_services AFTER STARTUP ON DATABASE

BEGIN

IF SYS_CONTEXT('USERENV','DATABASE_ROLE') = 'PRIMARY' THEN

DBMS_SERVICE.START_SERVICE('app_rw');

END IF;

END;

/

Client connect string with both hosts and fast failover:

SQL

app_rw = (DESCRIPTION=(CONNECT_TIMEOUT=5)(TRANSPORT_CONNECT_TIMEOUT=3)(RETRY_COUNT=3)

(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-a)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-b)(PORT=1521)))

(CONNECT_DATA=(SERVICE_NAME=app_rw)))

Why: clients follow the service, not the host; after a switchover app_rw simply appears on the other side. (With Grid Infrastructure use srvctl add service -role PRIMARY instead of the trigger.)

Monitoring queries

SQL

-- on the standby

SELECT name, value, datum_time FROM v$dataguard_stats; -- transport/apply lag

SELECT process, status, sequence# FROM v$managed_standby WHERE process LIKE 'MRP%' OR process LIKE 'RFS%';

SELECT * FROM v$dataguard_status WHERE timestamp > SYSDATE - 1/24 ORDER BY timestamp; -- recent messages

-- on the primary

SELECT dest_id, status, error, gap_status FROM v$archive_dest_status WHERE dest_id = 2;

DGMGRL

DGMGRL> SHOW DATABASE cdb23_b 'ApplyLag';

DGMGRL> SHOW DATABASE VERBOSE cdb23_b;

Operational checklist

Task

Note

Patching

Standby-first: patch the standby home, switch over, patch the old primary, switch back.

TDE key rotation

Copy the keystore to the standby immediately after SET KEY.

Adding a PDB / datafile

Automatic with STANDBY_FILE_MANAGEMENT=AUTO; a PDB created with STANDBYS=NONE is excluded on purpose.

Backups

Run RMAN backups on the standby with a recovery catalog to offload the primary.

Fast-Start Failover

Add an observer (START OBSERVER) and ENABLE FAST_START FAILOVER for automatic failover in MaxAvailability.

Broker files

DG_BROKER_CONFIG_FILE1/2 on shared storage for RAC.


Common errors

  • ORA-16664: unable to receive the result from a member → static listener entry or StaticConnectIdentifier wrong; run VALIDATE STATIC CONNECT IDENTIFIER FOR cdb23_b in DGMGRL.

  • ORA-16809: multiple warnings detected for the member → SHOW DATABASE cdb23_b lists them (usually missing SRLs or LogXptMode mismatch).

  • ORA-01017 during duplicate/transport → password file not copied or copied before a SYS password change.

  • Standby not applying: SHOW DATABASE cdb23_b says APPLY-OFF → EDIT DATABASE cdb23_b SET STATE = 'APPLY-ON';.

  • ORA-28365 on the standby → TDE keystore missing/closed; copy and auto-login it.

Recent Posts

See All

Comments


bottom of page