
Introduction
Oracle Data Guard provides high availability and disaster recovery by replicating data from the primary to standby databases. In case of an outage on the primary site or for maintenance operation, a standby database becomes a primary and continues serving application requests.
This role switch should be transparent for applications, not requiring any changes in the application configuration. Oracle recommends using the following connection string that includes the primary and standby address list and a single service name:
HR = (DESCRIPTION =
(CONNECT_TIMEOUT=120)(RETRY_COUNT=50)(RETRY_DELAY=3)
(TRANSPORT_CONNECT_TIMEOUT=3)
(ADDRESS_LIST =
(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=cluster1-scan)(PORT=1521)))
(ADDRESS_LIST =
(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=cluster2-scan)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME = hr.oracle.com)))
Using the default PDB or DB name is not recommended, as high availability attributes cannot be set for these services. Always create a custom service for your application and set high availability attributes accordingly.
The Environment
- Cross-region Oracle Data Guard on VM DB Systems in Oracle Cloud. Primary database in Frankfurt region in a VCN named vcnfra and standby database in Amsterdam region in a VCN named vcnams.
The Issue
The database domain is automatically attached to the service name when you create a service. Create a new service on the primary site:
-- on primary
SQL> select value from v$parameter where name='db_domain';
VALUE
------------------------------------------------------
subnet1.vcnfra.oraclevcn.com
-- create and start service
srvctl add service -db CDB01_fra3gh -service hr -pdb pdb01 -role primary
srvctl start service -db CDB01_fra3gh -service hr
-- check the service registered at the listener
lsnrctl services
...
Service "hr.subnet1.vcnfra.oraclevcn.com" has 1 instance(s).
...
The domain name “subnet1.vcnfra.oraclevcn.com” is of the format “<subnet_name>.<vnc_name>.oraclevcn.com”.
If the standby database is in another VCN, which is always the case in cross-region Data Guard deployments, creating the service on the standby site will result in a different service name.
-- on standby
SQL> select value from v$parameter where name='db_domain';
VALUE
------------------------------------------------------
subnet1.vcnams.oraclevcn.com
-- create and start service
srvctl add service -db CDB01_amsad1 -service hr -pdb pdb01 -role primary
srvctl start service -db CDB01_amsad1 -service hr
-- check the service registered at the listener
lsnrctl services
...
Service "hr.subnet1.vcnams.oraclevcn.com" has 1 instance(s).
...
In this case, we cannot use a single service name in the connection string as recommended above.
The Solution
Luckily, there is an easy solution. But let’s have a look at other options too:
Option 1: Use the same VCN and subnet names in the standby region
Not recommended as it might result in networking issues while connecting both VCNs via remote peering. In many cases, you will want to deploy your standby database in an already existing VCN anyway.
Option 2: Change the db_domain parameter in the database
Not recommended as it will break the Cloud Tooling automation used to manage your Data Guard environments via Cloud Console, OCI CLI, SDKs, or REST APIs.
Option 3: Use two service names in the connection string
While this works without any side effects, having two services in the connection string is tedious. Additionally, you still rely on the VCN and subnet names. If you migrate your primary or standby databases to another location with a different VCN, you will need to update the connection string for your applications:
HR = (DESCRIPTION_LIST =
(CONNECT_TIMEOUT=120)(RETRY_COUNT=50)(RETRY_DELAY=3)
(TRANSPORT_CONNECT_TIMEOUT=3)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cluster1-scan)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = hr.subnet1.vcnfra.oraclevcn.com))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cluster2-scan)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = hr.subnet1.vcnams.oraclevcn.com))
)
)
Option 4: Use a custom database domain while service creation
This is the recommended solution as of today. Include a domain name in the service name when you create the service, e.g., “hr.oracle.com” instead of just “hr”:
-- on primary
srvctl add service -db CDB01_fra3gh -service hr.oracle.com -pdb pdb01 -role primary
srvctl start service -db CDB01_fra3gh -service hr.oracle.com
lsnrctl services
...
Service "hr.oracle.com" has 1 instance(s).
...
-- on standby
srvctl add service -db CDB01_amsad1 -service hr.oracle.com -pdb pdb01 -role primary
srvctl start service -db CDB01_amsad1 -service hr.oracle.com
lsnrctl services
...
Service "hr.oracle.com" has 1 instance(s).
...
This will not impact Cloud Tooling and will allow you to use a single service name for both primary and standby databases, independent of the VCN and subnet names.
Option 5: Choose a custom database domain while creating the databases
Today, when you create a database on Oracle Cloud, the domain name is assigned automatically as described above. In the (near) future, there might be an enhancement to provide the option to choose your own domain name. Until then, just add your custom domain into the service name when you create your application services.
Exadata Cloud Service
In Exadata Cloud Service, when you create new PDBs using Cloud Tooling, an application service is created automatically in the format <cdb_name>_<pdb_name>.paas.oraclecloud.com, which can be used as a single service name for both primary and standby.
For additional services, add your custom domain name into the service as for VM DB Systems.
Conclusion
Creating a custom database service and not using the default PDB or DB name for your application is always recommended. Custom database services allow you to set up high availability and failover attributes. Use a single database service name on primary and standbys in Data Guard environments. In cross-region Data Guard configurations on VM DB System in the Oracle Cloud, include your custom domain name in the service name to achieve a single service name on all sites.
Further Reading
- Client Failover Best Practices for Highly Available Oracle Databases
- How to create a RAC Database Service With Physical Standby Role Option? (Doc ID 1129143.1)
- Part 4/5: Zero Downtime Migration (ZDM) – Physical Online Migration using Data Guard
- Hot Clone a remote PDB in Data Guard Environments using Transient no-standby PDBs
- The Journey of an Oracle Database Connection