Thursday, July 30, 2009

howto autostart database & listener under Solaris & Linux

whenever our office require to do some maintenance work, they ask us to take databases down, mostly it is on weekend and it turns to become a headache...we found that this thing is happening only or mostly with developer's environment database servers...so we decided to configure all developer's environment databases on autostart !

here is a small howto:

step 1: Modify oratab

For Solaris:

$vi /var/opt/oracle/oratab

For Linux:

$vi /etc/oratab

at the end of oratab file, you will see following lines :

SID1:/opt/oracle/product/oracle9i:N
SID2:/opt/oracle/product/oracle9i:N

replace above with:

SID1:/opt/oracle/product/oracle9i:Y
SID2:/opt/oracle/product/oracle9i:Y

step 2: Creating dbora.sh script

$vi /etc/init.d/dbora.sh

write following content in it:

#!/sbin/sh
ORACLE_HOME=/opt/oracle/product/oracle9i
ORACLE_OWNER=oracle

if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi

case "$1" in
'start') # Start the Oracle databases and listeners
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart"
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start"
;;
'stop') # Stop the Oracle databases and listeners
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut"
;;
esac

step 3: configure O.S to run dbora.sh on bootup/shutdown

For Solaris:

Link the dbora.sh to /etc/rc directories:

ln -s /etc/init.d/dbora.sh /etc/rc0.d/K10dbora
ln -s /etc/init.d/dbora.sh /etc/rc2.d/S99dbora

or

cp /etc/init.d/dbora.sh /etc/rc0.d/K10dbora

cp /etc/init.d/dbora.sh /etc/rc2.d/S99dbora

Note:we did cp on solaris 9. not sure but ln was not working.

For Linux:

$chkconfig --level 345 dbora.sh on

step 4: create pfile under $ORACLE_HOME/dbs --- OPTIONAL

if your database do not have pfile under $ORACLE_HOME/dbs you need to create by following command.

connect as "sysdba"

SQL> create pfile='$ORACLE_HOME/dba/initSID.ora' from spfile;

cheers

No comments: