Starting and Stopping Oracle Database Instances with SRVCTL

Affiliate Disclosure: This post contains affiliate links. Oracle Scripts may earn a commission if you buy through them, at no extra cost to you.

Starting and Stopping Oracle Database Instances with SRVCTL

Purpose

Planned work on one node of an Oracle RAC database begins with a small task. You stop the instance on that node, do the work, and start the instance again. The Server Control utility, srvctl, does this task from the command line. It starts or stops one named instance and leaves the other instances in the cluster as they are.

SRVCTL does more than send a shutdown command. It starts and stops instances by configuring and managing Oracle Clusterware resources. Those resources define agents that run the database startup and shutdown. This is the reason to prefer SRVCTL over a manual SQL*Plus session on a cluster node.

A DBA runs these commands for patching, for hardware work, for a parameter change that needs a restart, and for recovery after a failed instance. The sections below show the commands, explain each option, compare the shutdown modes, and list the checks to make before you stop a production node.

Code

1srvctl start instance -d <database name> -i <instance name>
1srvctl stop instance -d <database name> -i <instance name>

The same two commands with the full keyword form of each parameter. Use this form in new scripts.

1srvctl start instance -db <db_unique_name> -instance <instance name>
1srvctl stop instance -db <db_unique_name> -instance <instance name> -stopoption IMMEDIATE

Code Breakdown

Command structure

  • srvctl <command> <object> [parameters] is the general form. The command is a verb such as start or stop. The object is the target, such as database or instance.
  • start or stop is the action. Commands, object names and parameters are case sensitive, so type them in lower case as shown.
  • instance is the object. It limits the action to one instance, or to a list of instances, and not to the whole database.
  • -d and -i are the older single-letter forms of -db and -instance. Oracle deprecated single-character parameters in 12c. The current SRVCTL still accepts both forms, so old scripts keep working. New scripts should use the full keywords.
  • -db is the unique name of the database.
  • -instance is the name of one instance. A comma-delimited list of names is also accepted when the database is administrator-managed.
  • -node is an alternative to -instance for policy-managed databases. You name the node, and SRVCTL finds the instance that runs there.

Start options

The start command takes -startoption. Typical values are OPEN, MOUNT and NOMOUNT. Some options have two words, such as read only. For these, separate the words with a space and put them in double quotation marks:

1srvctl start instance -db <db_unique_name> -instance <instance name> -startoption "read only"

Stop options

The stop command takes -stopoption. This option passes the shutdown mode to the shutdown command. The values are NORMAL, TRANSACTIONAL LOCAL, IMMEDIATE and ABORT. The next section compares the modes.

Other parameters of the stop command:

  • -force stops the instance and any running services if the first attempt fails with an error. Use it after a plain stop has failed, not as the first choice.
  • -failover makes the services fail over to an available instance, or start a new instance, when the current instance stops.
  • -drain_timeout sets the time, in seconds, that the agent has to finish draining the services. If you set it to zero, the agent acts on the draining at once.

Key Points

  • Log in as the right operating system user. To change the configuration of a database with SRVCTL, you log in to the operating system as the software owner of the Oracle home you want to manage. Members of the OSDBA operating system group can start and stop the database.
  • SRVCTL needs Clusterware. The start instance and stop instance commands are available only with Oracle Clusterware and Oracle RAC. They are not for a single instance with no cluster.
  • RAC One Node is different. On an Oracle RAC One Node database, both commands return an error. The error tells you to use the database object. Use srvctl start database or srvctl stop database for these systems.
  • Stopping an instance stops its services. The srvctl stop instance command stops the instance and any services that run on it.
  • A stop with -node and no -db is wide. If you give a node but no database name, all instances that run on that node are stopped, whatever database they belong to. Check the node before you press Enter.
  • Start also handles listeners. The srvctl start instance command starts the database instances and all listeners on nodes that have database instances.

Insights and Best Practices

Choose the shutdown mode on purpose

The mode you pass in -stopoption decides how long the stop takes and what the next start must do. The SQL*Plus SHUTDOWN command defines the modes, and SRVCTL passes them through. These are the facts that matter:

  • NORMAL is the default in SQL*Plus. It waits for users to disconnect from the database. When the instance shuts down this way, no instance recovery is needed on the next startup. On a busy system, a stop with this mode can wait a long time, because one session that stays connected holds it.
  • TRANSACTIONAL LOCAL allows active transactions on the local instance to finish first. No client can start a new transaction on that instance. After the transactions finish, the clients that are still connected are disconnected, and the instance shuts down as it would after SHUTDOWN IMMEDIATE. The LOCAL mode waits only for local transactions, not all transactions. Oracle notes this is useful for scheduled outage maintenance. The next startup needs no instance recovery.
  • IMMEDIATE does not wait for current calls to complete or for users to disconnect. The database is closed and dismounted, and no instance recovery is needed on the next startup.
  • ABORT is the fastest shutdown. It does not wait for calls to complete or users to disconnect. Uncommitted transactions are not rolled back, and the next startup needs instance recovery. Keep it for cases where nothing else works, for example when a background process has ended abnormally.

For planned maintenance on one node, TRANSACTIONAL LOCAL is a good first choice, because users on that instance finish their work and the other instances keep running. Use IMMEDIATE when you cannot wait for the transactions.

Use the full keywords in scripts

Old scripts with -d and -i still run, because the current SRVCTL accepts both forms. Even so, change them when you next edit them. The keyword form is the documented form, and it is easier to read in a change review.

Stop one instance, then check the rest

Stopping an instance is only half of the task. After the stop, confirm that the other instances still run and that the services moved where you expect. You can use srvctl status instance to verify the state of an instance. Run it for the instance you stopped and for its neighbours. Oracle documents that you can use SRVCTL to verify that instances are running on a particular database.

Start and stop everything with the database object

To start or stop all the instances of a cluster database in one step, use srvctl start database and srvctl stop database. Oracle Enterprise Manager offers the same one-step option. Use the instance object only when you want to leave other instances alone. A full database stop is also needed for some changes. For example, to switch the archiving mode, Oracle's procedure shuts the instances down, starts the database in the mount state, runs ALTER DATABASE ARCHIVELOG, and then opens the database. Oracle states that the database must be mounted but not open for this change. On a cluster, the stop and the mount-state start can both be done with srvctl stop database and srvctl start database -startoption mount.

Know what happens to services

When you stop an instance, SRVCTL stops the services that run on it. With -failover, the services fail over to an available instance. List the services on the instance before maintenance, so that you know which ones will move. Then check them again after the start. The SRVCTL reference lists the service commands.

SQL*Plus is the alternative, not the first choice

You can still start and stop an instance with the STARTUP and SHUTDOWN commands in SQL*Plus. You must connect as SYSDBA, SYSOPER, SYSBACKUP or SYSDG to run SHUTDOWN. On a cluster node, use SRVCTL instead, so that the stop and start go through the Clusterware resources described above.

Preview before you stop a node

Before a stop on a production node, run a short check list:

  1. Confirm the database unique name and the instance name. Do not rely on memory.
  2. Confirm the node. Remember that -node without -db stops every instance on that node.
  3. Decide the stop option and write it in the command. Do not leave it to the stored default.
  4. Know the services on the instance and decide if you need -failover.
  5. Run the status command for all instances after the stop and again after the start.

When to Run This

  • Planned maintenance on one node: operating system patching, firmware updates, memory changes or network work.
  • Rolling changes: a change that must be applied to one instance at a time, so that the database stays available.
  • Parameter changes that need a restart: after you change a static parameter in the server parameter file.
  • Recovery after an instance failure: to start the instance that failed after you fix the cause.
  • Bringing a node back into the cluster: after the node returns from repair.
  • Testing: to confirm that your services fail over as designed before the real maintenance window.

Troubleshooting Common Issues

The command returns an error on a RAC One Node database. Both the start and stop instance commands return an error here and tell you to use the database object. Run srvctl start database or srvctl stop database instead.

You are told you have no permission. Check the operating system user. The user must be the software owner of the Oracle home you manage. Log in as that user and try again.

The stop fails with an error. Read the error text first. If you decide to continue, add -force, which stops the instance and any running services after the first attempt has failed. Treat this as a second step, and check afterwards that the services are where you expect.

A NORMAL stop does not finish. The mode waits for all users to disconnect. A session that stays connected can hold it. Use TRANSACTIONAL LOCAL or IMMEDIATE next time, or find the sessions that remain and ask their owners to disconnect.

The next start takes longer than usual. If you stopped with ABORT, the next startup needs instance recovery. This is expected. Wait for the recovery to finish and check the alert log for progress.

A service did not come back after the start. List the services on the instance and check the state of each one. Start the missing ones by hand, and review the service settings before the next maintenance.

The wrong instance was stopped. This usually comes from a mix-up between the database name and the unique name, or from a -node option with no -db. Start the instance again with the same command pattern and then correct your runbook.

Related books recommended

Links go to Amazon. As an Amazon Associate, Oracle Scripts earns from qualifying purchases; your price is unchanged.

References

Posts in this series