Data Guard between DC and DR

Oracle 19c physical standby with the Data Guard broker: redo shipping from the DC primary to the DR standby, a planned switchover, and a failover you can reinstate.

Updated CompTech Team

A site failure needs a transactionally consistent copy already at the DR. Data Guard keeps it: the DC primary ships redo, and a physical standby applies it. This lab builds that pair on Oracle 19c and rehearses a switchover and a failover. Ramen moves the OpenShift workloads. Data Guard moves the database. A node dying inside one site is an Oracle restart, or RAC if you run it.

Prerequisites

  • Two Oracle 19c homes at the same release and patch, one at each site. The examples use DB_NAME=orcl, DB_UNIQUE_NAME=orcldc on host oradc, and orcldr on host oradr.
  • The DC database in ARCHIVELOG mode, with a fast recovery area that can hold redo that has not shipped yet.
  • Port 1521 open each way, and TNS aliases orcldc and orcldr on both hosts.
  • The same SYS password file on both. The broker logs in with it.
  • Flashback database on, so a failed primary can be reinstated.

Prepare the primary

Standby redo logs have to exist before the duplicate. Create one more group than you have online redo groups, each the same size as an online log. Repeat per thread on RAC.

ALTER DATABASE FORCE LOGGING;
ALTER DATABASE FLASHBACK ON;
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO SCOPE=BOTH;
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcldc,orcldr)' SCOPE=BOTH;
ALTER SYSTEM SET DG_BROKER_START=TRUE SCOPE=BOTH;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1
  GROUP 10 ('/u01/oradata/orcl/srl10.log') SIZE 200M;

Match SIZE to V$LOG.BYTES and add groups until standby groups = online groups + 1. The broker starts a down instance through a static listener entry. GLOBAL_DBNAME is <db_unique_name>_DGMGRL:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcldc_DGMGRL)
      (ORACLE_HOME = /u01/app/oracle/product/19c/dbhome_1)
      (SID_NAME = orcl)
    )
  )

Use orcldr_DGMGRL on the DR host. lsnrctl reload on both.

Build the standby

Start the DR instance NOMOUNT with a pfile that sets only db_name=orcl, then duplicate from the live primary. NOFILENAMECHECK is for identical paths. When the paths differ, set DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT and drop NOFILENAMECHECK.

rman TARGET sys@orcldc AUXILIARY sys@orcldr
DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER
  SPFILE
    SET db_unique_name='orcldr'
    SET fal_server='orcldc'
  NOFILENAMECHECK;

On the new standby:

ALTER SYSTEM SET DG_BROKER_START=TRUE SCOPE=BOTH;

Broker

dgmgrl sys@orcldc
CREATE CONFIGURATION 'orcldg' AS
  PRIMARY DATABASE IS 'orcldc' CONNECT IDENTIFIER IS orcldc;
ADD DATABASE 'orcldr' AS CONNECT IDENTIFIER IS orcldr MAINTAINED AS PHYSICAL;
ENABLE CONFIGURATION;
SHOW CONFIGURATION;
VALIDATE DATABASE orcldr;

SUCCESS on the configuration and both databases is the healthy line. VALIDATE DATABASE reports a missing standby redo log before a switchover does.

How far behind the DR is allowed to be

Mode Redo transport What a commit does
Maximum Performance ASYNC Returns when the local online log is written. The standby can be behind.
Maximum Availability SYNC with AFFIRM, and it falls back if the standby is unreachable Waits for the standby while the standby answers.
Maximum Protection SYNC, and the primary stops if no standby can affirm For the case where a stalled primary is acceptable and a lost commit is not.

Between two cities, Maximum Performance is the usual setting. SYNC adds a round trip to every commit.

EDIT DATABASE orcldc SET PROPERTY LogXptMode='ASYNC';
EDIT DATABASE orcldr SET PROPERTY LogXptMode='ASYNC';
EDIT CONFIGURATION SET PROTECTION MODE AS MAXPERFORMANCE;
SELECT name, value FROM v$dataguard_stats
 WHERE name IN ('transport lag','apply lag');

A transport lag that keeps growing means the link or the standby is behind. Clear it before you call the pair ready.

A service that follows the primary

Applications connect with SERVICE_NAME=orcl_rw, a service that starts only on the primary. A host name in the connect string still points at the old site after a switchover.

BEGIN
  DBMS_SERVICE.CREATE_SERVICE('orcl_rw','orcl_rw');
END;
/
CREATE OR REPLACE TRIGGER start_rw_service AFTER STARTUP ON DATABASE
DECLARE
  role VARCHAR2(30);
BEGIN
  SELECT database_role INTO role FROM v$database;
  IF role = 'PRIMARY' THEN
    DBMS_SERVICE.START_SERVICE('orcl_rw');
  END IF;
END;
/

Create the service and the trigger on the primary before the duplicate, so the standby already has them.

Switchover and failover

Both databases are up for a switchover. The old primary becomes the standby.

SWITCHOVER TO orcldr;
SHOW CONFIGURATION;

Insert a row through orcl_rw and confirm the session landed on oradr. Switch back with SWITCHOVER TO orcldc when the drill is done.

Fail over only when the primary is gone and can no longer accept writes. When the old site returns, reinstate it. Flashback has to cover the failover.

FAILOVER TO orcldr;
REINSTATE DATABASE orcldc;

If reinstate refuses, the flashback window was too short or the old primary was opened for writes. Recovery is a fresh duplicate. The row through orcl_rw proves the service moved. V$DATAGUARD_STATS is the check you keep.

What's next

Ramen backup covers the OpenShift workloads that call this database. The PostgreSQL version of a standby and a promote is the Crunchy DC/DR lab. Change data capture off the primary is the Kafka series.