Automatic Startup – Shutdown database ORACLE 11g

9 Dec

1. create script start database
[oracle@mkt ~]$ cd $ORACLE_HOME/bin
[oracle@mkt bin]$ vi startora11g
#!/bin/sh
# Start the oracle database
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1
export ORACLE_SID=mkt
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export ORACLE_TERM=xterm
$ORACLE_HOME/bin/dbstart
exit 0

[oracle@mkt bin]$ chmod u+x startora11g

2. create script stop database
[oracle@mkt ~]$ cd $ORACLE_HOME/bin
[oracle@mkt bin]$ vi stopora11g
#!/bin/sh
# Stop the oracle database
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1
export ORACLE_SID=mkt
export ORACLE_TERM=xterm
$ORACLE_HOME/bin/dbshut
exit 0
[oracle@mkt bin]$ chmod u+x stopora11g

3. create script restart, start & stop
[oracle@mkt ~]$ cd $ORACLE_HOME/bin
[oracle@mkt bin]$ vi oracle11g
#!/bin/sh
#
# chkconfig: 345 51 49
# description: startup and shutdown the Oracle 8i database
#
echo “Oracle 11g database start/stop/restart”
ORA_OWNER=oracle
ORA_BASE=/u01/app/oracle
ORA_HOME=$ORA_BASE/product/11.1.0/db_1

case “$1” in
‘start’)
# Start the database
echo -n “Starting the database for 11g: ”
su – $ORA_OWNER -c $ORA_HOME/bin/startora11g
echo
;;

‘stop’)
# Stop the database
echo -n “Shutting down database for 11g: ”
su – $ORA_OWNER -c $ORA_HOME/bin/stopora11g
echo
;;

‘restart’)
# Restart the Oracle databases:
echo -n “Restarting database for 11g: ”
$0 stop
$0 start
echo
;;
*)

echo “Usage: oracle11g [ start | stop | restart }”
exit 1
esac
exit 0
[oracle@mkt bin]$ chmod u+x oracle11g

4. Login root & edit /etc/oratab.
[oracle@mkt bin]$ su – root
Password:
[root@mkt ~]# vi /etc/oratab
mkt:/u01/app/oracle/product/11.1.0/db_1:N
menjadi
mkt:/u01/app/oracle/product/11.1.0/db_1:Y

5. copy script oracle11g to /etc/rc.d/init.d/
[root@mkt ~]# cp /u01/app/oracle/product/11.1.0/db_1/bin/oracle11g /etc/rc.d/init.d/
[root@mkt ~]# chmod 700 /etc/rc.d/init.d/oracle11g

6. test script oracle11g start, stop, restart with login as root
[root@mkt ~]# cd /etc/rc.d/init.d
[root@mkt init.d]# ./oracle11g
Oracle 11g database start/stop/restart
Usage: oracle11g [ start | stop | restart }

[root@mkt init.d]# ./oracle11g start
Oracle 11g database start/stop/restart
Starting the database for 11g: ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/11.1.0/db_1/bin/dbstart ORACLE_HOME
Processing Database instance “mkt”: log file /u01/app/oracle/product/11.1.0/db_1/startup.log

[root@mkt init.d]# ./oracle11g stop
Oracle 11g database start/stop/restart
Shutting down database for 11g: ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener
Usage: /u01/app/oracle/product/11.1.0/db_1/bin/dbshut ORACLE_HOME
Processing Database instance “mkt”: log file /u01/app/oracle/product/11.1.0/db_1/shutdown.log

[root@mkt init.d]# ./oracle11g restart
Oracle 11g database start/stop/restart
Restarting database for 11g: Oracle 11g database start/stop/restart
Shutting down database for 11g: ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener
Usage: /u01/app/oracle/product/11.1.0/db_1/bin/dbshut ORACLE_HOME
Processing Database instance “mkt”: log file /u01/app/oracle/product/11.1.0/db_1/shutdown.log

Oracle 11g database start/stop/restart
Starting the database for 11g: ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/11.1.0/db_1/bin/dbstart ORACLE_HOME
Processing Database instance “mkt”: log file /u01/app/oracle/product/11.1.0/db_1/startup.log

7. chkconfig pada script oracle11g
[root@mkt init.d]# /sbin/chkconfig –add oracle11g
[root@mkt init.d]# /sbin/chkconfig –list oracle11g
oracle11g 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@mkt init.d]# /sbin/chkconfig oracle11g on

4 Responses to “Automatic Startup – Shutdown database ORACLE 11g”

  1. Fabio April 17, 2009 at 1:46 pm #

    Muito bom, muito bom mesmo, tks…
    Very good, very good yes, tks…

  2. Jack Nickolson May 4, 2010 at 8:37 pm #

    Hi,

    Does it working for all unix and linux versions?

  3. wilder jorge zegarra July 12, 2012 at 8:37 pm #

    Este script me ayudo a terminar de instalar mi servidor Oracle 11g; no sabia como configurar el startup y el shutdown. Gracias. Wilder

  4. Ishanka Ranasooriya November 7, 2013 at 7:27 am #

    I did it auto start and stop in this way

    1-Edit the #vi /etc/oratabfile :
    orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y

    then

    vi /etc/init.d/oracle

    paste this script to it and save

    #!/bin/bash
    #
    # oracle This shell script takes care of starting and stopping
    # the Oracle subsystem (oracle).
    #
    # chkconfig: – 64 36
    # description: Oracle database server.
    # processname: oracle
    # pidfile: /var/run/oracle/oracle.pid
    ### BEGIN INIT INFO
    # Provides: oracle
    # Required-Start: $local_fs $remote_fs $network $named $syslog $time
    # Required-Stop: $local_fs $remote_fs $network $named $syslog $time
    # Short-Description: start and stop Oracle server
    # Description: Oracle database server
    ### END INIT INFO

    # Source function library.
    . /etc/rc.d/init.d/functions

    # Source networking configuration.
    . /etc/sysconfig/network

    start() {
    if [ -e /var/lock/subsys/oracle ];then
    echo “Starting Oracle Enterprise Server”
    failure
    else
    echo “Starting Oracle Enterprise Server”
    success
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Starting Oracle Listeners” >> /var/log/oracle/oracle.log
    su – oracle -c “lsnrctl start” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Starting Oracle Databases” >> /var/log/oracle/oracle.log
    su – oracle -c “dbstart” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Starting Oracle Enterprise Manager” >> /var/log/oracle/oracle.log
    su – oracle -c “emctl start dbconsole” >> /var/log/oracle/oracle.log
    touch /var/lock/subsys/oracle
    fi
    }

    stop() {
    if [ -f /var/lock/subsys/oracle ];then
    echo “Shutting Down Oracle Enterprise Server”
    success
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Shutting Down Oracle Enterprise Manager” >> /var/log/oracle/oracle.log
    su – oracle -c “emctl stop dbconsole” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Shutting Down Oracle Listeners” >> /var/log/oracle/oracle.log
    su – oracle -c “lsnrctl stop” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Shutting Down Oracle Databases” >> /var/log/oracle/oracle.log
    su – oracle -c “dbshut” >> /var/log/oracle/oracle.log
    rm -f /var/lock/subsys/oracle
    else
    echo “Shutting Down Oracle Enterprise Server”
    failure
    fi
    }

    case “$1” in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    if [ -e /var/lock/subsys/oracle ]; then
    echo -n “Oracle Enterprise Server is Running”
    success
    echo
    else
    echo -n “Oracle Enterprise Server is Not Running”
    failure
    echo
    fi
    ;;
    restart)
    stop
    sleep 2
    start
    ;;
    *)
    echo $”Usage: $0 {start|stop|restart|status}”
    exit 1

    esac
    exit 0

    then
    chkconfig –add oracle
    chkconfig oracle on

    Cheers Your done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: