Oracle Data Guard Most Used Commands

Note: Static “_DGMGRL” entries are no longer needed as of Oracle Database 12.1.0.2 and later release in Oracle Data Guard Broker configurations that are managed by Oracle Restart, RAC On Node or RAC as the Broker will use the clusterware to restart an instance. ( Oracle Data Guard Broker and Static Service Registration (Doc ID 1387859.1)

DGMGRL> connect sys@testdb
Password:
Connected to "TESTDB"
Connected as SYSDBA.
DGMGRL> show configuration;

Configuration - dg_testdb

Protection Mode: MaxPerformance
Members:
testdb - Primary database
stestdb - Physical standby database

Fast-Start Failover: Disabled

Configuration Status:
SUCCESS (status updated 20 seconds ago)

Switchover

DGMGRL> switchover to stestdb;
Performing switchover NOW, please wait...
New primary database "stestdb" is opening...
Oracle Clusterware is restarting database "testdb" ...
Connected to "TESTDB"
Switchover succeeded, new primary is "stestdb"

-- After switchover, run 'srvctl config database -d", the database role has been changed by Data Guard Broker automatically.

$ srvctl config database -d STESTDB
Database unique name: STESTDB
Database name: testdb
.
Start options: open
Stop options: immediate
Database role: PRIMARY

...
..
.

$ srvctl config database -d testdb
Database unique name: TESTDB
Database name: TESTDB
.
Start options: mount
Stop options: immediate
Database role: PHYSICAL_STANDBY

Show Lag

DGMGRL>  SHOW CONFIGURATION  lag

Configuration - dg_testdb

Protection Mode: MaxPerformance
Members:
testdb - Primary database
stestdb - Physical standby database
Transport Lag: 0 seconds (computed 0 seconds ago)
Apply Lag: 2 seconds (computed 0 seconds ago)

Fast-Start Failover: Disabled

Configuration Status:
SUCCESS (status updated 28 seconds ago)
DGMGRL> show database "stestdb";

Database - stestdb

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: 322.00 KByte/s
Real Time Query: OFF
Instance(s):
TESTDB1
TESTDB2 (apply instance)

Database Status:
SUCCESS

TRANSPORT-ON / TRANSPORT-OFF

DGMGRL>  show database "testdb";

Database - testdb

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

Database Status:
SUCCESS

DGMGRL> EDIT DATABASE testdb SET STATE='TRANSPORT-OFF';
Succeeded.
DGMGRL> show database "testdb";

Database - testdb

Role: PRIMARY
Intended State: TRANSPORT-OFF
Instance(s):
TESTDB1
TESTDB2

Database Status:
SUCCESS

APPLY-ON / APPLY-OFF

DGMGRL>  show database "stestdb";

Database - stestdb

Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 70 seconds ago)
Apply Lag: 0 seconds (computed 70 seconds ago)
Average Apply Rate: 114.00 KByte/s
Real Time Query: OFF
Instance(s):
TESTDB1
TESTDB2 (apply instance)

Database Status:
SUCCESS

DGMGRL> EDIT DATABASE stestdb SET STATE='APPLY-OFF';
Succeeded.
DGMGRL> show database "stestdb";

Database - stestdb

Role: PHYSICAL STANDBY
Intended State: APPLY-OFF
Transport Lag: 0 seconds (computed 215 seconds ago)
Apply Lag: 0 seconds (computed 215 seconds ago)
Average Apply Rate: (unknown)
Real Time Query: OFF
Instance(s):
TESTDB1
TESTDB2 (apply instance)

Database Status:
SUCCESS

Change apply instance

DGMGRL> edit database  TESTDB set state='apply-off';
Succeeded.

DGMGRL> edit database TESTDB set state='apply-on' with apply instance ='TESTDB1';

Succeeded.

Monitorable (Read-Only) Properties

DGMGRL>   show database verbose testdb;
...
..
.
InconsistentProperties = '(monitor)'
InconsistentLogXptProps = '(monitor)'
LogXptStatus = '(monitor)'
SendQEntries = '(monitor)'
RecvQEntries = '(monitor)'
...
..
.

DGMGRL> show database testdb 'InconsistentLogXptProps';
INCONSISTENT LOG TRANSPORT PROPERTIES
INSTANCE_NAME STANDBY_NAME PROPERTY_NAME MEMORY_VALUE BROKER_VALUE

Configurable (Changeable) Properties

DGMGRL>  SHOW DATABASE testdb  LogXptMode;
LogXptMode = 'ASYNC'

DGMGRL> EDIT DATABASE testdb SET PROPERTY LogXptMode='SYNC';
Property "logxptmode" updated

DGMGRL> SHOW DATABASE testdb LogXptMode;
LogXptMode = 'SYNC'

Validate database spfile

DGMGRL> validate database  TESTDB  spfile;
This command cannot be used for the primary database.

DGMGRL> validate database STESTDB spfile;
...
..
.

processes:
testdb (PRIMARY) : 3000
stestdb : 6400
...
..
.

Validate static connect identifier

DGMGRL> validate static connect identifier for all
Oracle Clusterware on database "testdb" is available for database restart.

Oracle Clusterware on database "stestdb" is available for database restart.

validate network configuration for all

DGMGRL> validate network configuration for all
Oracle Clusterware on database "testdb" is available for database restart.

Oracle Clusterware on database "stestdb" is available for database restart.

DGMGRL> validate network configuration for all
Connecting to instance "TESTDB2" on database "testdb" ...
Connected to "TESTDB"
Checking connectivity from instance "TESTDB2" on database "testdb" to instance "STESTDB2" on database "stestdb"...
Succeeded.
Checking connectivity from instance "TESTDB2" on database "testdb" to instance "STESTDB" on database "stestdb"...
Succeeded.
Connecting to instance "TESTDB1" on database "testdb" ...
Connected to "TESTDB"
Checking connectivity from instance "TESTDB1" on database "testdb" to instance "STESTDB2" on database "stestdb"...
Succeeded.
Checking connectivity from instance "TESTDB1" on database "testdb" to instance "STESTDB" on database "stestdb"...
Succeeded.
Connecting to instance "STESTDB2" on database "stestdb" ...
Connected to "STESTDB"
Checking connectivity from instance "STESTDB2" on database "stestdb" to instance "TESTDB2" on database "testdb"...
Succeeded.
Checking connectivity from instance "STESTDB2" on database "stestdb" to instance "TESTDB1" on database "testdb"...
Succeeded.
Connecting to instance "STESTDB" on database "stestdb" ...
Connected to "STESTDB"
Checking connectivity from instance "STESTDB" on database "stestdb" to instance "TESTDB2" on database "testdb"...
Succeeded.
Checking connectivity from instance "STESTDB" on database "stestdb" to instance "TESTDB1" on database "testdb"...
Succeeded.

Oracle Clusterware on database "testdb" is available for database restart.

Oracle Clusterware on database "stestdb" is available for database restart.

DGMGRL>

Validate primary and standby database

DGMGRL> validate database testdb

Database Role: Primary database

Ready for Switchover: Yes

Flashback Database Status:
ttestdb: Off

Managed by Clusterware:
testdb: YES

DGMGRL> validate database stestdb

Database Role: Physical standby database
Primary Database: testdb

Ready for Switchover: Yes
Ready for Failover: Yes (Primary Running)

Flashback Database Status:
testdb: Off
stestdb: Off

Managed by Clusterware:
testdb: YES
stestdb: YES

Oracle Duplicate a Database from a Standby Database

This post demonstrates how to duplicate an Oracle database from a standby database instead of from a primary database normally.

The environment list:

Primaey DBStandby DBDulicate DB
TESTDBSTBYDBDUDB

Assume that all tnsnames are already configured. Password file, spfile are also already configured as the following:

  1. Copy the password file from source database for the target database, or create a password file with the same password as source db.
  2. Add “(UR = A)” into source and target tnsnames.
  3. Add an entry into listener.ora for auxiliary instance static registration. You can create a temporary listener with a spare port without changing anything of the current listener.
  4. CLUSTER_DATABASe=false in spfile for auxiliary instance.

Please note when you create the password file, you have to add the database into cluster OCR first, otherwise the following errors will occur:

ASMCMD> pwcreate --dbuniquename DUPDB '+DATA2/DUPDB/password/pwddupdb'
Enter password: ***********
OPW-00021: Failed to retrieve DB password file location from the CRS resource
ASMCMD-9454: could not create new password file
$ srvctl add database -d DUPDB -oraclehome /u01/app/oracle/product/19.0.0/dbhome_1  -dbtype RAC  -domain world  -spfile +DATA2/DUPDB/PARAMETERFILE/spfileDUPDB.ora   -role PRIMARY  -startoption OPEN  -stopoption IMMEDIATE


ASMCMD> pwcreate --dbuniquename DUPDB '+DATA2/DUPDB/password/pwddupdb'
Enter password: ***********

$ srvctl modify database -db DUPDB -pwfile '+DATA2/DUPDB/password/pwddupdb'


-- The following error will occur if the database is not added into CRS before creating the password file:

ASMCMD> pwcreate --dbuniquename DUPDB '+DATA2/DUPDB/password/pwddupdb'
Enter password: ***********
OPW-00021: Failed to retrieve DB password file location from the CRS resource
ASMCMD-9454: could not create new password file

Start Up Duplicate Database in Nomount

SQL> startup nomount pfile='/tmp/initDUPDB.ora' ;

SQL> create spfile='+DATA2/DUPDB/PARAMETERFILE/spfileDUPDB.ora' from pfile='/tmp/initDUPDB1.ora' ;

$ cat $ORACLE_HOME/dbs/initDUPDB1.ora
spfile='+DATA2/DUPDB/PARAMETERFILE/spfileDUPDB.ora'

SQL> startup database nomount force;

Duplicate database when standby in Read Only Mode

$ srvctl stop database -db STBYDB

$ srvctl start database -db STBYDB -startoption "READ ONLY"

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY WITH APPLY


SQL> alter database recover managed standby database cancel;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ ONLY

$ rman target sys@stbydb auxiliary sys@dupdb
target database Password:
connected to target database: STDBYDB (DBID=123456789)
auxiliary database Password:
connected to auxiliary database: DUPDB (not mounted)

RMAN> duplicate target database to DUPDB from active database ;
...
...
.
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 03-APR-25

RMAN>

Duplicate database when standby in Recovery( Mounted and Applying ) Mode

DGMGRL>  show configuration;

Configuration - dg_testdb

Protection Mode: MaxPerformance
Members:
testdb - Primary database
stbydb - Physical standby database

Fast-Start Failover: Disabled

Configuration Status:
SUCCESS (status updated 56 seconds ago)


DGMGRL> show database verbose "stbydb";

Database - stbydb

Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 0 seconds ago)
Apply Lag: 0 seconds (computed 1 second ago)
Average Apply Rate: 3.40 MByte/s
Active Apply Rate: 12.61 MByte/s
Maximum Apply Rate: 12.89 MByte/s
Real Time Query: OFF
Instance(s):
STBYDB1 (apply instance)
STBYDB2
...
Database Status:
SUCCESS

DGMGRL>
$ rman  target sys@stbydb auxiliary sys@dupdb
target database Password:
connected to target database: STBYDB (DBID=123456789)
auxiliary database Password:
connected to auxiliary database: DUPDB (not mounted)

RMAN> duplicate target database to DUPDB from active database ;
...
...
.
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 03-APR-25

RMAN>

Duplicate database when standby in Non-Recovery ( Mounted and Non-applying ) Mode

DGMGRL> show database verbose "stbydb"
Database - stbydb

Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 0 seconds ago)
Apply Lag: 12 hours 39 minutes 52 seconds (computed 0 seconds ago)
Average Apply Rate: 46.00 KByte/s
Active Apply Rate: 1.17 MByte/s
Maximum Apply Rate: 12.89 MByte/s
Real Time Query: OFF
Instance(s):
STBYDB1 (apply instance)
STBYDB2

Database Error(s):
ORA-16766: Redo Apply is stopped

Database Warning(s):
ORA-16853: apply lag has exceeded specified threshold

...
..
.
Database Status:
ERROR

DGMGRL>
$ rman  target sys@stbydb auxiliary sys@dupdb
target database Password:
connected to target database: STDBYDB (DBID=123456789)
auxiliary database Password:
connected to auxiliary database: DUPDB (not mounted)

RMAN> duplicate target database to DUPDB from active database ;
...
...
.
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 03-APR-25

RMAN>

From the above tests, we can see the duplicate process will

1) switch archivelogs on PRIMARY
2) copy archived logs onto new duplicated database
3) apply the archived logs onto new database finally before OPEN new database.

so, no matter standby database is either

1) OPEN READ ONLY MODE
2) MOUNTED and RECOVERY MODE
3) MOUNTED and NON RECOVERY MODE

DUPLICATE from standby database all works well.

The common errors and solutions

RMAN-04006: error from auxiliary database: ORA-12528: TNS:listener: all appropriate instances are blocking new connections

This error is generated because STATIC REGISTRATION on listener was not done. To fix this, we need to add an entry of SID_LIST_LISTENER into listener.ora.

RMAN-04006: error from auxiliary database: ORA-12537: TNS:connection closed

This error was generated by missing the (UR = A) from tnsnames.

RMAN-04006: error froRMAN-06136: Oracle error from auxiliary database: ORA-17629: Cannot connect to the remote database server
ORA-17627: ORA-01017: invalid username/password; logon denied
ORA-17629: Cannot connect to the remote database serverm auxiliary database: ORA-01017: invalid username/password; logon denied

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 04/03/2025 15:29:36
RMAN-05501: aborting duplication of target database
RMAN-03015: error occurred in stored script Memory Script
RMAN-06136: Oracle error from auxiliary database: ORA-17629: Cannot connect to the remote database server
ORA-17627: ORA-01017: invalid username/password; logon denied
ORA-17629: Cannot connect to the remote database server
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 04/03/2025 16:28:42
RMAN-05501: aborting duplication of target database
RMAN-05614: Passwords for target and auxiliary connections must be the same when using active duplicate

This error is because password file was not copied to duplicate database, or the password is different.

ORA-12720: operation requires database is in EXCLUSIVE mode

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 04/03/2025 16:50:17
RMAN-05501: aborting duplication of target database
RMAN-06136: Oracle error from auxiliary database: ORA-01503: CREATE CONTROLFILE failed
ORA-12720: operation requires database is in EXCLUSIVE mode

set parameter “cluster_database=FALSE”