How to Restart Oracle Database

  • by

In this post, we'll talked about how to restart a database in a efficient way, which includes:

  1. Restart a Single-Instance DB
  2. Restart a RAC DB

A. Restart a Single-instance Database

Normally, we take two steps to restart a running database, which are shutdown and startup.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
...
Database mounted.
Database opened.

We can also use Oracle utility dbstart to restart the database in only one command. But first, you have to make sure that you enable it to do so.

[oracle@test ~]$ vi /etc/oratab
...
ORCL:/u01/app/oracle/product/12.1.0/dbhome_1:Y

You have to set the database to Y to allow dbstart to do shutdown and startup.

1. Check Startup Time Before Restart

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

SQL> select startup_time from v$instance;

STARTUP_TIME
-------------------
2019-09-20 21:56:52

2. Perform a Restart

[oracle@test ~]$ dbstart

3. Check Startup Time After Restart

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

SQL> select startup_time from v$instance;

STARTUP_TIME
-------------------
2019-09-20 22:09:03

That is to say, if the database is stop, dbstart will try to start it. If the database is running, dbstart will stop it first then a startup follows automatically.

I guess maybe you also want to know how to deploy auto startup script at system boot on Linux.

Restart a RAC Database

For a RAC database, there's no explicit restart command for us to use. We usually do it in two steps:

[oracle@test ~]$ srvctl stop database -d testcdb
[oracle@test ~]$ srvctl start database -d testcdb

Then check the status.

[oracle@test ~]$ srvctl status database -d testcdb

If you do mind this matter, you can do the following consecutive command to remove the execution gap between stop and start without waiting.

[oracle@test ~]$ srvctl stop database -d testcdb; srvctl start database -d testcdb; srvctl status database -d testcdb

Leave a Reply

Your email address will not be published. Required fields are marked *