• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Automate Startup/Shutdown of Oracle Database and Listener on Linux

by admin

In many environments, it’s desirable to have the Oracle database and listener automatically shutdown and startup when the server reboots. If you have that requirement, then follow the next several steps to automate your database and listener shutdown and startup:

Steps to configure auto startup/shutdown

1. Edit the /etc/oratab file, and place a Y at the end of the entry for the databases you want to automatically restart when the system reboots. You might need root privileges to edit the file:

# vi /etc/oratab
[SID]:[ORACLE_HOME]:Y

The Y on the end of the string signifies that the database can be started and stopped by the ORACLE_HOME/bin/dbstart and ORACLE_HOME/bin/dbshut scripts.

Note: with some Unix systems (such as Solaris), the oratab file is usually located in the /var/opt/oracle directory.

2. Create the service script /etc/init.d/dbora. Content of the script is as follows. Make sure you change the values of variables ORA_HOME and ORA_OWNER to match your environment. This is a bare bones script of what you minimally would need to stop and start a database and listener:

# vi /etc/init.d/dbora
#!/bin/bash
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes
ORA_HOME=/oracle/app/oracle/product/11.2.0/db_1
ORA_OWNER=oracle
case "$1" in
  'start')
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
    su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
   ;;
  'stop')
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
    su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
   ;;
esac

# End of script dbora

Understanding the script

The lines:

# chkconfig: 35 99 10
# description: Starts and stops Oracle database

are mandatory and not just comments since they describe the characteristics of the service where:

  • 35 means that the service will be started in init levels 3 and 5 and will be stopped in other levels.
  • 99 means that the service will be started at the near end of the init level processing
  • 10 means that the service will be stopped at the near beginning of the init level processing

Rest of the script is pretty easy to understand. The first case starts the listener/DB whereas the 2nd case stops it. Follow the steps below to make script executable and enable to run automatically when system boots up.

Make script executable and Enable to run on boot

1. Change the group of the dbora file to match the group assigned to the operating system owner of the Oracle software (usually oinstall or dba):

# chgrp dba /etc/init.d/dbora

2. Set the script permissions to 755.

# chmod 750 /etc/init.d/dbora

3. Run the following chkconfig command:

# chkconfig --add dbora

This action registers the service to the Linux service mechanism. This also creates the appropriate symbolic links to files beneath the /etc/rc.d directory. Use the –list option to display whether a service is on or off for each runlevel:

# chkconfig --list | grep dbora
dbora           0:off   1:off   2:off   3:on    4:off   5:on    6:off

This output indicates the dbora service is on for runlevels 3 and 5. If you need to delete a service, use the –del option of chkconfig.

Testing the script

1. To test whether the dbora script is working, as root run the following to stop your database and listener:

# /etc/init.d/dbora stop

2. To test the startup of your database and listener, as root issue the following command:

# /etc/init.d/dbora start

Final Thoughts

Automating the shutdown and startup of your Oracle database will vary depending on whether you’re using tools like cluster software or ASM. The solution in this section demonstrates the typical steps to implement the shutdown and startup of your database in the scenarios where you don’t have other software that manages this task.

Filed Under: CentOS/RHEL 4, CentOS/RHEL 5, CentOS/RHEL 6, Fedora, Linux, OEL 6

Some more articles you might also be interested in …

  1. check-support-status: Command Examples in Linux
  2. CentOS / RHEL : How to create a Thinly Provisioned Logical Volume
  3. CentOS / RHEL 7 : How to disable Transparent Huge pages (THP)
  4. How to disable or enable an HBA without reboot under CentOS/RHEL
  5. logrotate Command Examples in Linux
  6. How to install rsyslog7 when rsyslog5 is already installed in CentOS/RHEL
  7. mkfs.vfat Command Examples in Linux
  8. i3: command not found
  9. rpm: error while loading shared libraries: invalid ELF header
  10. Downgrading an rpm package to a lower version (using “rpm” command)

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright