cancel
Showing results for 
Search instead for 
Did you mean: 

Oracle dbshut and dbstart

John Curtis
Occasional Advisor

Oracle dbshut and dbstart

I recently moved two separate database to a single HP server. They each have their own oracle home. I have one oracle user and when I log in I must state the oracle sid I want to connect to. Problem, the file or script /sbin/init.d/oracle that would normally shutdown and startup a database during reboot uses "su - oracle -c dbshut" and "su - oracle -c dbstart" which only connects to one instance.
I use oraenv to create the user parameters and set oraenv_ask to yes so that when I log into the oracle user I'm prompted for the SID.
How might I create a script that can log into both database and issue the dbshut and dbstart as needed?
4 REPLIES
Sridhar Bhaskarla
Honored Contributor

Re: Oracle dbshut and dbstart

Hi John,

You may have to modify your dbshut and dbstart commands to add something like this.

ORATAB=/etc/oratab

for SID in $(awk '{FS=":";print $1}' $ORATAB)
do
echo "Shutting down the instance $SID"
export ORACLE_SID=$SID
(your_oracle_shutdown|startup commands)
done

Same for startup.


You may be disappointed if you fail, but you are doomed if you don't try
Indira Aramandla
Honored Contributor

Re: Oracle dbshut and dbstart

John,

You can add the following lines to your dbshut and dbstart.

You should have entries in oratab for the two databases with the ORACLE_HOME and the third parameter "Y" defined.

Then add the following to DBSHUT script.
cat $ORATAB | while read LINE
do
case $LINE in
\#*) ;; #comment-line in oratab
*)
# Proceed only if third field is 'Y'.
if [ "`echo $LINE | awk -F: '{print $3}' -`" = "Y" ] ; then
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
if [ "$ORACLE_SID" = '*' ] ; then
ORACLE_SID=""
fi
# Called programs use same database ID
export ORACLE_SID
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
# Called scripts use same home directory
export ORACLE_HOME
# Put $ORACLE_HOME/bin into PATH and export.
PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/etc ; export PATH

PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
echo "Shutting down the instance $SID"
svrmgrl << EOF
connect internal
shutdown immediate
EOF

Add the same lines in your dbstart script except for after server manager login startup.
echo appropriate messages where necessary.


Never give up, Keep Trying
PAVIC Thierry
Frequent Advisor

Re: Oracle dbshut and dbstart

Hi,

the main way is to list all your database
show file /etc/oratab


in a Shell script use an order like this
L_BaseLst=`awk -F: '/^[^#*]/{print $1}' /etc/oratab | sort`


after you have to read your list

for L_BaseTmp in ${L_BaseLst}
do
# -- Check the status
ps -ef|grep ora_pmon_${L_BaseTmp}|grep -v grep >/dev/null
if [ $? -gt 0 ]
then
echo "ERR - database ${L_BaseTmp} is closed"
else
echo "\n\n ----> database ${L_BaseTmp}"

su - ${ORA_USR} -c "ORACLE_SID=${L_BaseTmp}; sqlplus system/${SystemPwd} shutdown immediate"

fi
done

This the a way, you have to modify this lines in order to put some logs file, or mail alert.

best regards Thierry
SGUX
Valued Contributor

Re: Oracle dbshut and dbstart

we use the following line in /sbin/init.d/oracle;
su - oracle -c ". [path] SID;dbshut"
and this works fine