When deploying a FlashGrid Cluster with Oracle RAC database nodes spread across Availability Zones (AZs) on AWS, Azure, or Google Cloud, client connections are distributed across all database nodes by default. As a result, part of the traffic between clients (e.g. app servers) and the database crosses AZ boundaries.
Availability Zone affinity keeps the client traffic within the AZ where the client is located. It is configured with database services whose preferred instance runs on the database node in each AZ. This will help to:
- Reduce data transfer costs. Cloud providers may charge for data transferred between AZs. Check the current pricing of your cloud provider for inter-AZ data transfer.
- Reduce client latency. The network latency between a client and a database node in the same AZ is typically lower than the inter-AZ latency.
The trade-off is the loss of load balancing across AZs: during normal operation, the clients in each AZ are served by the database node in that AZ. Review the Trade-offs section before configuring Availability Zone affinity.
Note: This article applies to multi-AZ 2-node and 3-node clusters, with each database node in its own AZ. The same approach applies to database nodes deployed in AWS Local Zones, see AWS Local Zones.
Overview
For each AZ, a separate database service is created. The database instance running in that AZ is configured as the preferred instance of the service. The database instances running in the other AZs are configured as available instances, so that the service fails over to another AZ if the preferred instance is down. When the preferred instance is up again, the service fails back to it automatically.
The clients in each AZ connect using the service name of their AZ. The initial connection request is sent to the SCAN listener on any of the database nodes. The SCAN listener redirects the connection to the local listener of the database node where the service is running. The initial connection request may be sent to a database node in another AZ, but the database session is established with the database node in the same AZ as the client.
Trade-offs
- No load balancing across AZs. During normal operation, the clients in each AZ are served by the single database node in that AZ. If one AZ has more clients or a heavier workload, the database node in that AZ carries more load while the other database nodes are underused.
-
Failover moves the traffic to another AZ. If the preferred instance of a service is down, the service fails over to an available instance in another AZ. The service remains available, but its traffic crosses AZ boundaries, and the database node running the service serves the clients of its own AZ and of the AZ where the preferred instance is down. The cost and latency benefits return when the service fails back to its preferred instance, see After a failover.
Size the database nodes for failover. In a 2-node cluster, each database node must handle the peak load of both AZs. In a 3-node cluster, if one database node fails, the clients of its AZ move to a single other database node, so each database node must handle the peak load of two AZs. If two database nodes fail, the remaining database node serves the clients of all three AZs.
- Workloads that require load balancing. For workloads where load balancing across all database nodes is more important than data transfer costs and latency, use a separate service with all database instances configured as preferred instances.
Prerequisites
- The cluster is a multi-AZ cluster with two or three database nodes, each placed in its own AZ.
- The database is Oracle Database 19c or later.
- Make sure database clients are configured using one of the methods described in Connecting Database Clients or Connecting Database Clients using SCAN address (alternative method).
- Identify the AZ of each database node in the cloud console.
-
Identify the database instance running on each database node. Run the command below as the oracle user. The output has one line per database instance. Example output for a 2-node cluster:
$ srvctl status database -db racdb Instance racdb1 is running on node rac1 Instance racdb2 is running on node rac2 -
Run the queries below in SQL*Plus as SYSDBA to check whether the database is a container database (CDB) and identify the pluggable database (PDB) that the clients connect to. If the first query returns NO, the database is not a CDB: skip the second query and do not specify the
-pdbparameter when creating the services.SQL> select cdb from v$database; CDB --- YES SQL> select name from v$pdbs where name <> 'PDB$SEED'; NAME ------------------------------ PDB1
If the CDB contains more than one PDB, create the services in the PDB that the clients connect to.
- Identify the AZ of each client that connects to the database.
The examples below use the database racdb: the instance racdbN runs on the node racN in the AZ number N, and the service for that AZ is named racdb_azN. Examples are provided for 2-node and 3-node clusters. Replace these names with the corresponding names of your cluster.
Create database services
Create one service for each AZ. Specify the database instance in that AZ as the preferred instance, and all other database instances as available instances. Each database instance is the preferred instance of exactly one service.
List the available instances in priority order. In a 3-node cluster, rotate the order so that each database instance is the first available instance of exactly one other service. This distributes the load evenly if a database node fails.
Specify -failback YES for each service, so that the service automatically fails back to its preferred instance when the preferred instance becomes available.
Service configuration for a 2-node cluster:
| AZ | Node | Instance | Service | Preferred | Available |
|---|---|---|---|---|---|
| AZ1 | rac1 | racdb1 | racdb_az1 | racdb1 | racdb2 |
| AZ2 | rac2 | racdb2 | racdb_az2 | racdb2 | racdb1 |
Service configuration for a 3-node cluster:
| AZ | Node | Instance | Service | Preferred | Available |
|---|---|---|---|---|---|
| AZ1 | rac1 | racdb1 | racdb_az1 | racdb1 | racdb2,racdb3 |
| AZ2 | rac2 | racdb2 | racdb_az2 | racdb2 | racdb3,racdb1 |
| AZ3 | rac3 | racdb3 | racdb_az3 | racdb3 | racdb1,racdb2 |
Run the commands below as the oracle user.
-
Create the services. For a 2-node cluster:
$ srvctl add service -db racdb \ -service racdb_az1 \ -preferred racdb1 \ -available racdb2 \ -failback YES $ srvctl add service -db racdb \ -service racdb_az2 \ -preferred racdb2 \ -available racdb1 \ -failback YES
For a 3-node cluster:
$ srvctl add service -db racdb \ -service racdb_az1 \ -preferred racdb1 \ -available racdb2,racdb3 \ -failback YES $ srvctl add service -db racdb \ -service racdb_az2 \ -preferred racdb2 \ -available racdb3,racdb1 \ -failback YES $ srvctl add service -db racdb \ -service racdb_az3 \ -preferred racdb3 \ -available racdb1,racdb2 \ -failback YES
If the database is a CDB, add the
-pdbparameter with the PDB name identified in the Prerequisites section to each command, e.g.:$ srvctl add service -db racdb \ -service racdb_az1 \ -preferred racdb1 \ -available racdb2 \ -failback YES \ -pdb PDB1 -
Start each created service. For a 2-node cluster:
$ srvctl start service -db racdb -service racdb_az1 $ srvctl start service -db racdb -service racdb_az2
For a 3-node cluster:
$ srvctl start service -db racdb -service racdb_az1 $ srvctl start service -db racdb -service racdb_az2 $ srvctl start service -db racdb -service racdb_az3
-
Check that each service is running on its preferred instance. Example output for a 2-node cluster:
$ srvctl status service -db racdb Service racdb_az1 is running on instance(s) racdb1 Service racdb_az2 is running on instance(s) racdb2
Configuring client connect string
Configure the clients in each AZ to use the service name of their AZ in the connect string: the clients in the AZ number N use the service racdb_azN. For example, in a 3-node cluster:
- Clients in AZ1: racdb_az1
- Clients in AZ2: racdb_az2
- Clients in AZ3: racdb_az3
Keep the rest of the connect string unchanged. The connect string configured as described in the articles referenced in the Prerequisites section allows the clients to connect to the service even if the database node in their AZ is down.
The services can also be configured for TAF (Transparent Application Failover) or Transparent Application Continuity (TAC) to reduce the impact of a failover on the application.
Testing client connectivity
From a client in AZ1, connect using the service racdb_az1 and determine the database instance to which the session is connected:
SQL> select host_name, instance_name from v$instance;
HOST_NAME INSTANCE_NAME
------------------------------ ----------------
rac1.example.com racdb1
Repeat the test from a client in each of the other AZs using the service of that AZ. The session must be connected to the database instance in the same AZ as the client, e.g. a client in AZ2 using the service racdb_az2 must be connected to the instance racdb2.
After a failover
If the preferred instance of a service goes down, the service fails over to an available instance in another AZ. With -failback YES, the service automatically fails back to its preferred instance when the preferred instance becomes available. New connections to the service are established with the preferred instance after the service fails back.
AWS Local Zones
The same approach applies to database nodes deployed in AWS Local Zones. Create a service with the database instance in the Local Zone as the preferred instance, and configure the clients in that Local Zone to use this service name. For deploying a cluster in Local Zones, see Deploying FlashGrid Cluster in AWS Local Zones.
Troubleshooting
For additional information on troubleshooting client connections, see Troubleshooting: Client connection failing.
Related articles
- Connecting Database Clients
- Connecting Database Clients using SCAN address (alternative method)
- Selecting Availability Zones to minimize latency between Oracle RAC nodes on AWS
- Selecting Availability Zones to minimize latency between Oracle RAC nodes on Azure
- Selecting Availability Zones to minimize latency between Oracle RAC nodes on Google Cloud
- Deploying FlashGrid Cluster in AWS Local Zones