Linux Automatic Start Oracle
Oracle provides two UNIX / Linux scripts that assist DBAs with starting and stopping the database: dbstart and dbshut.For Windows platforms, the oradim utility is provided for automatically starting and stopping the Oracle instance. The dbstart utility reads the oratab file, shown in the example below. The oratab file will reside in either /etc or /var/opt/oracle, depending on the UNIX.
8i 9i 10g 11g 12c 13c 18c 19c Misc PL/SQL SQL RAC WebLogic Linux
Home » Articles » Linux » Here
If you are using Oracle Clusterware 10gR2 or above for RAC or just for a single instance using ASM, the Clusterware automatically starts and stops the Oracle database instances and listeners, so the following procedures are not necessary. Where the Clusterware is not being used, these methods allow you to automate the startup and shutdown of databases on Linux.
These methods work on all RHEL and Oracle Linux versions up to and including RHEL7/OL7.
Related articles.
What I Use
This article contains a number of variations, but this is what I currently use, which is a variation on the 'su' command.
The scripts are created using the cat
command, with all the '$' characters escaped. If you want to manually create these files, rather than using the cat
command, remember to remove the ' characters before the '$' characters.
Create a 'scripts' directory.
Create an environment file called 'setEnv.sh'. This is an example from a 12.2 installation. Adjust the contents according to your installation.
Add a reference to the 'setEnv.sh' file at the end of the '/home/oracle/.bash_profile' file if you want the settings to be applied for a normal login. The profile will not be set during the start/stop of a service, so this is not necessary for the automatic start/stop functionality.
Create a 'start_all.sh' and 'stop_all.sh' script that can be called from a startup/shutdown service. Make sure the ownership and permissions are correct.
You should be able to start/stop the database with the following scripts run from the 'oracle' user.
Now we need to create the Linux service to call the scripts we created previously. The reset of this section represents what I so for OL6, but it will also work for OL7. If you are using OL7 and prefer to use systemd directly, you can follow the instructions provided here.
Create a file called '/etc/init.d/dbora' as the root user, containing the following.
Use the chmod
command to set the privileges to 750.
Associate the 'dbora' service with the appropriate run levels and set it to auto-start using the following command.
You can start and stop the database using the service, which is what will happen on a reboot.
systemd Services
With the introduction of RHEL7/OL7, services are now managed using systemd. You can continue to use the existing methods shown below for creating a service to auto-start Oracle, as systemd is backwards compatible. If you prefer to use systemd directly, you can follow the instructions provided here.
The systemd example assumes you have the scrips defined above in the '/home/oracle/scripts/' directory present.
The 'su' Command
The following method for automating database startup and shutdown of Oracle instances on Linux works equally well for Oracle 9i, 10g, 11G and 12c. It can be used on any RHEL-style distribution, including Oracle Linux, up to an including RHEL7. I still use this method for Oracle 12c on OL6. It will work for RHEL7/OL7, but I prefer to use the systemd services.
Once the instance is created, edit the '/etc/oratab' file setting the restart flag for each instance to 'Y'.
Create a file called '/etc/init.d/dbora' as the root user, containing the following code. Adjust the paths to match your system.
Use the chmod
command to set the privileges to 750.
Associate the 'dbora' service with the appropriate run levels and set it to auto-start using the following command.
The relevant instances should now startup/shutdown automatically at system startup/shutdown.
For Oracle 9i the dbstart
and dbshut
commands didn't control the listener, so listener management had to be done separately, as shown below.
The 'rsh' Command
Some of the Oracle 10g documentation recommends using the 'rsh' command in the 'dbora' service. Later database versions switched back to using the 'su' command. I have never liked or used this approach on a real system.
With Oracle 10g, Oracle switched from recommending the 'su' command to the 'rsh' command. In Oracle 10g release 2, the dbstart
command includes an automatic start of the listener, so there are some differences between the two versions, but the following represents Oracle's preferred method for Oracle 10g.
Once the instance is created, edit the '/etc/oratab' file setting the restart flag for each instance to 'Y'.
Create a file called '/etc/init.d/dbora' as the root user, containing the following.
Use the chmod
command to set the privileges to 750.
Associate the 'dbora' service with the appropriate run levels and set it to auto-start using the following command.
The relevant instances should now startup/shutdown automatically at system startup/shutdown.
This method relies on the presence of an RSH server, which requires additional packages and configuration.
This can be quite problematic when attempting to use this method under later Linux distributions, where rsh is deprecated. As a result, I prefer to use the 'su' command method.
This method can also be used for 11g databases that are not using ASM or RAC.
The 'runuser' Command
Oracle Start Command
For a time the Oracle 12c documentation recommended using the 'runuser' command in the 'dbora' service. The latest version of the documents have reverted the using the 'su' command. An example of using the 'runuser' command is shown below, but I don't use this.
Once the instance is created, edit the '/etc/oratab' file setting the restart flag for each instance to 'Y'.
Create a file called '/etc/init.d/dbora' as the root user, containing the following code, which is a modified version of the example from the documentation, which doesn't work.
If you want the service to wait while the startup completes, remove the '&'. This is especially important for shutdowns that take a long time, like when shutting down WebLogic and Cloud Control services.
Use the chmod
command to set the privileges to 750. Associate the 'dbora' service with the appropriate run levels and set it to auto-start using the following command.
Known Issues
When using Oracle 10g Release 2, calling dbstart
without the '$ORACLE_HOME' might result in the following error message.
Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr
This is due to a hard coded path in the dbstart
script. You should not see this error if you pass the '$ORACLE_HOME' as a parameter to dbstart and dbshut. To correct this, edit the '$ORACLE_HOME/bin/dbstart' script and replace the following line (approximately line 78).
With this.
The dbstart
script should now start the listener as expected.
dbstart and dbshut Deprecation?
The Oracle 11gR2 documentation states the use of the dbstart
and dbshut
scripts are deprecated. The preferred replacement is Oracle Restart.
Both dbstart
and dbshut
are still present in Oracle 11gR2, so you can continue to use them (I still use them). In order to use Oracle Restart you must install Grid Infrastructure (GI), which you will already have if you are using RAC or ASM for a standalone instance. In these cases, Oracle Restart will already be present and running. For single instance databases that don't use ASM, I think it is unreasonable to expect people to install GI.
The Oracle 12c documentation has no mention of the deprecation of dbstart
and dbshut
and has reinstated the documentation about them. As a result, you are free to use dbstart
and dbshut
in a supported manner for all versions of the database.
For more information see:
Hope this helps. Regards Tim...
Photo courtesy of Rob Shenk
For a DBA, starting up and shutting down of oracle database is a routine and basic operation. Sometimes Linux administrator or programmer may end-up doing some basic DBA operations on development database. So, it is important for non-DBAs to understand some basic database administration activities.
In this article, let us review how to start and stop an oracle database.
How To Startup Oracle Database
1. Login to the system with oracle username
Typical oracle installation will have oracle as username and dba as group. On Linux, do su to oracle as shown below.
2. Connect to oracle sysdba
Make sure ORACLE_SID and ORACLE_HOME are set properly as shown below.
You can connect using either “/ as sysdba” or an oracle account that has DBA privilege.
3. Start Oracle Database
The default SPFILE (server parameter file) is located under $ORACLE_HOME/dbs. Oracle will use this SPFILE during startup, if you don’t specify PFILE.
Oracle will look for the parameter file in the following order under $ORACLE_HOME/dbs. If any one of them exist, it will use that particular parameter file.
- spfile$ORACLE_SID.ora
- spfile.ora
- init$ORACLE_SID.ora
Type “startup” at the SQL command prompt to startup the database as shown below.
If you want to startup Oracle with PFILE, pass it as a parameter as shown below.
How To Shutdown Oracle Database
Following three methods are available to shutdown the oracle database:
- Normal Shutdown
- Shutdown Immediate
- Shutdown Abort
1. Normal Shutdown
During normal shutdown, before the oracle database is shut down, oracle will wait for all active users to disconnect their sessions. As the parameter name (normal) suggest, use this option to shutdown the database under normal conditions.
2. Shutdown Immediate
During immediate shutdown, before the oracle database is shut down, oracle will rollback active transaction and disconnect all active users. Use this option when there is a problem with your database and you don’t have enough time to request users to log-off.
3. Shutdown Abort
During shutdown abort, before the oracle database is shutdown, all user sessions will be terminated immediately. Uncomitted transactions will not be rolled back. Use this option only during emergency situations when the “shutdown” and “shutdown immediate” doesn’t work.