Configuring and Monitoring Data Guard in Oracle Cloud Databases
High Availability and Disaster Recovery are critical requirements for enterprise workloads in Oracle Cloud Infrastructure (OCI). Oracle Data Guard provides replication and failover capabilities for Oracle Databases, ensuring business continuity in case of planned or unplanned outages.
This blog explains how to configure Data Guard in OCI and how to monitor its status using both OCI CLI and database queries.
Step 1: Enable Data Guard in OCI
Data Guard can be enabled for Bare Metal or VM DB systems in OCI. The following command enables Data Guard on an existing database:
oci db data-guard-association create with-new-db-system \
--database-id ocid1.database.oc1.ap-mumbai-1.abcdexample \
--creation-type NewDbSystem \
--database-admin-password Welcome123# \
--protection-mode MAXIMUM_PERFORMANCE \
--transport-type ASYNC \
--peer-db-system-id ocid1.dbsystem.oc1.ap-mumbai-1.xyzaexample \
--compartment-id ocid1.compartment.oc1..aaaaexample
Sample output
{
"data": {
"id": "ocid1.dataguardassociation.oc1.ap-mumbai-1.abcdefexample",
"lifecycle-state": "CREATING",
"protection-mode": "MAXIMUM_PERFORMANCE",
"transport-type": "ASYNC",
"role": "PRIMARY"
}
}
The Data Guard association is created and the standby database will begin syncing.
Step 2: Check Data Guard Association
After creation, check the status of Data Guard:
oci db data-guard-association list \
--database-id ocid1.database.oc1.ap-mumbai-1.abcdexample
Sample output
{
"data": [
{
"id": "ocid1.dataguardassociation.oc1.ap-mumbai-1.abcdefexample",
"lifecycle-state": "AVAILABLE",
"role": "PRIMARY",
"peer-role": "STANDBY",
"protection-mode": "MAXIMUM_PERFORMANCE",
"transport-type": "ASYNC"
}
]
}
Interpretation: The primary database is healthy and the standby database is available.
Step 3: Monitor Data Guard Using SQL
Log in to the primary database and run:
SELECT dest_id,
status,
protection_mode,
synchronization_status,
error
FROM v$archive_dest_status
WHERE dest_id = 2;
Sample output
DEST_ID STATUS PROTECTION_MODE SYNCHRONIZATION_STATUS ERROR
------- --------- ------------------- ---------------------- -----
2 VALID MAXIMUM PERFORMANCE SYNCHRONIZED
Interpretation: The Data Guard destination is valid and synchronized.
Step 4: Monitor Redo Apply on Standby
On the standby database, check the managed recovery process:
SELECT process, status, thread#, sequence#
FROM v$managed_standby
WHERE process LIKE 'MRP%';
Sample output
PROCESS STATUS THREAD# SEQUENCE#
--------- -------- ------- ---------
MRP0 APPLYING 1 14523
Interpretation: The Managed Recovery Process (MRP) is actively applying redo logs from the primary database.
Step 5: Monitor Apply Lag
To check if the standby is lagging behind the primary:
SELECT name, value, unit
FROM v$dataguard_stats
WHERE name IN ('transport lag','apply lag');
Sample output
NAME VALUE UNIT
-------------- ----- ----------------
transport lag +00 00:00:05
apply lag +00 00:00:08
Interpretation: Transport lag is 5 seconds, apply lag is 8 seconds. This is normal for asynchronous mode.
Step 6: Perform a Switchover
For planned maintenance, you may perform a switchover:
oci db data-guard-association switchover \
--database-id ocid1.database.oc1.ap-mumbai-1.abcdexample \
--data-guard-association-id ocid1.dataguardassociation.oc1.ap-mumbai-1.abcdefexample
Sample output
{
"data": {
"id": "ocid1.dataguardassociation.oc1.ap-mumbai-1.abcdefexample",
"lifecycle-state": "UPDATING",
"role": "STANDBY",
"peer-role": "PRIMARY"
}
}
After completion, the roles of primary and standby databases are reversed.
Step 7: Perform a Failover
For unplanned outages, a failover can be executed:
oci db data-guard-association failover \
--database-id ocid1.database.oc1.ap-mumbai-1.abcdexample \
--data-guard-association-id ocid1.dataguardassociation.oc1.ap-mumbai-1.abcdefexample
Sample output
{
"data": {
"id": "ocid1.dataguardassociation.oc1.ap-mumbai-1.abcdefexample",
"lifecycle-state": "UPDATING",
"role": "PRIMARY",
"protection-mode": "MAXIMUM_PERFORMANCE"
}
}
The standby database is promoted to primary and the original primary is disabled.
Best Practices
- Always configure Data Guard in a separate availability domain or region for disaster recovery.
- Regularly check apply lag to ensure standby is in sync.
- Test switchovers periodically to validate readiness.
- Automate monitoring using OCI CLI and scheduled scripts.
- Integrate alerts with OCI Monitoring and Notification services for proactive detection.
Conclusion
Configuring and monitoring Data Guard in Oracle Cloud Databases is essential for ensuring high availability and disaster recovery. Using OCI CLI for configuration and database views for monitoring gives Cloud Ops DBAs complete control over replication, synchronization, and role transitions. By following a structured monitoring routine, you can ensure your databases remain resilient and ready for failover at any time.
No Comments