Manage Oracle RAC Services on Multiple Nodes
How to Manage Oracle RAC Services on Multiple Nodes: A Step-by-Step Guide
In this blog, I will walk you through how to manage Oracle RAC services on multiple nodes using simple scripts. This approach can help streamline the process of starting, stopping, and modifying services across your RAC cluster.
Oracle Real Application Clusters (RAC) is a high-availability and scalability solution that allows multiple instances of Oracle Database to run on different nodes. Managing services in Oracle RAC can sometimes become cumbersome, especially when dealing with multiple nodes and services. By using automation scripts, you can efficiently control the services without manual intervention.
The Importance of Oracle RAC Service Management
When you have a complex Oracle RAC configuration involving multiple nodes, managing the services can become a tedious task. Ensuring that services are running on the preferred nodes or starting services on all nodes is crucial for maintaining optimal performance. Here’s where automation comes in.
The following scripts can be used to start, stop, and configure services in an Oracle RAC environment efficiently.
1. Script to Start Services on a Specific Node
The first step in managing services in Oracle RAC is starting them on a specific node. This script allows you to easily start services on any given node.
#!/bin/bash
# Define Oracle database and service names
DB_NAME="rohit-db"
SERVICES=("appservice1" "appservice2" "appservice3") # Add all your services here
NODE="rohit-node1" # Replace with your node name
# Loop through all services and start them on the specified node
for SERVICE in "${SERVICES[@]}"
do
echo "Starting service $SERVICE on node $NODE..."
srvctl start service -d $DB_NAME -s $SERVICE -i $NODE
if [ $? -eq 0 ]; then
echo "Service $SERVICE started successfully on $NODE."
else
echo "Failed to start service $SERVICE on $NODE."
fi
done
Explanation: This script loops through all the services you specify, and it starts each service on the specified node (rohit-node1).
2. Script to Start Services on Both Nodes
If you need to start services on both nodes in your Oracle RAC cluster, you can use this script. It will loop through both nodes and start all services on each node.
#!/bin/bash
# Define Oracle database and service names
DB_NAME="rohit-db"
SERVICES=("appservice1" "appservice2" "appservice3") # Add all your services here
NODES=("rohit-node1" "rohit-node2") # List of nodes to start services on
# Loop through each node
for NODE in "${NODES[@]}"
do
# Loop through all services and start them on the current node
for SERVICE in "${SERVICES[@]}"
do
echo "Starting service $SERVICE on node $NODE..."
srvctl start service -d $DB_NAME -s $SERVICE -i $NODE
if [ $? -eq 0 ]; then
echo "Service $SERVICE started successfully on $NODE."
else
echo "Failed to start service $SERVICE on $NODE."
fi
done
done
Explanation: This script ensures that each service is started on both nodes (rohit-node1 and rohit-node2). It uses two loops to iterate over both nodes and start the services.
3. Script to Modify Service Preferences (Setting Preferred Nodes)
In Oracle RAC, you may need to set the preferred nodes for services to ensure that they run on specific nodes. Use the following script to configure preferred nodes for your services
Example of the updated script with author information:
#!/bin/bash
# =======================================================================
# Script Name: start_services.sh
# Author: Rohit Mishri
# Description: Script to start specified Oracle services on a RAC cluster
# =======================================================================
# List of services to start
services=("appservice1" "appservice2" "appservice3")
# Loop through each service and start it
for service in "${services[@]}"; do
echo "Starting service: $service"
srvctl start service -d rohit-test -s $service
done
echo "All services started successfully!"
Example for the other script:
#!/bin/bash
# =======================================================================
# Script Name: modify_service.sh
# Author: Rohit Mishri
# Description: Script to modify the preferred instances for Oracle services
# =======================================================================
# Specify the services
services=("appservice1" "appservice2" "appservice3")
# Loop through each service and modify the preferred instances
for service in "${services[@]}"; do
echo "Modifying preferred instances for service: $service"
srvctl modify service -d rohit-test -s $service -i rohit-node1,rohit-node2
done
echo "Service modifications completed!"
How to implement:
- You can copy and paste these scripts to your desired location.
- Replace
rohit-testwith the actual database name, and adjust the node names (rohit-node1,rohit-node2) and services (appservice1,appservice2,appservice3) as per your environment. oracle rac database
Author: Rohit Mishri
