After following the first three posts about Oracle installation, you should finish installing Oracle successfully. We will further discuss how to start up and shutdown Oracle related services manually and automatically in this post.
Manually
1) Start up
Login as oracle user and start sqlplus utility.
SQL > startup
Start Oracle listener
Start emctl (Optional)
$ emctl start dbconsole
Start web browser and log into the console
2) Shutdown
Login as oracle user and start sqlplus utility.
Stop listener
Stop Oracle server
SQL > shutdown immediate
Stop emctl
$ emctl stop dbconsole
Automatically
1) Modify Oracle system configuration to enable dbstart and dbshut
$su - oracle $vi /etc/oratab
2) Create Oracle startup&shutdown script in /etc/init.d. The sample script is attached below.
#!/bin/sh #chkconfig: 35 80 99 # description: Oracle auto start-stop script. # # Set ORA_HOME to be equivalent to the $ORACLE_HOME # from which you wish to execute dbstart and dbshut; # # Set ORA_OWNER to the user id of the owner of the # Oracle database in ORA_HOME. ORA_HOME=/pdm/db/oracle/product/11.2.0/dbhome_1 ORA_OWNER=oracle if [ ! -f $ORA_HOME/bin/dbstart ] then echo "Oracle startup: cannot start" exit fi case "$1" in 'start') # Start the Oracle databases: echo "Starting Oracle Databases and listener ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" >>/var/log/oracle echo "Done" # Start the Listener: #echo "Starting Oracle Listeners ... " #echo "-------------------------------------------------" >> /var/log/oracle #date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle #echo "-------------------------------------------------" >> /var/log/oracle #su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle #echo "Done." #echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle touch /var/lock/subsys/oracle ;; 'stop') # Stop the Oracle Listener: #echo "Stoping Oracle Listeners ... " #echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Listener and Server as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle #su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle #echo "Done." rm -f /var/lock/subsys/oracle # Stop the Oracle Database: echo "Stoping Oracle Databases and Listener... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME" >>/var/log/oracle echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle ;; 'restart') $0 stop $0 start ;; esac
3)Change script mode to 755
# chmod 755 /etc/init.d/oracle
4) Add oracle service
# chkconfig –level 35 oracle on
5)Create symbolic links for oracle shutdown on run level 0 and 6
#for run level 0 (shutdown)
# ln -s /etc/init.d/oracle /etc/rc0.d/K99oracle # for run level 6 (restart)
# ln -s /etc/init.d/oracle /etc/rc6.d/K99oracle
Reference Material
The following urls are useful about Oracle services startup and shutdown.
http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html (Linux下chkconfig命令详解)
http://www.cnblogs.com/mchina/archive/2012/11/27/2782993.html (Linux Oracle服务启动&停止脚本与开机自启动)
http://www.linuxidc.com/Linux/2007-06/4892.htm (实现linux在关机或重启时自动执行某个任务)
http://www.cnblogs.com/bangerlee/archive/2012/03/30/2412652.html (Linux进程托管与守护进程设置)