Home > dba_scripts > script to startup single instance oracle database

script to startup single instance oracle database

#!/bin/ksh
#——————————————————————
# name : oradbstart.ksh
# This script is used to shudown oracle database
# Arguments $1 = ORACLE_SID(Required)
# Argument $2 = open,mount(optional)
# If argument 2 is not specified then default open
# usage: orashutdb.ksh <ora sid> [<startup type>]
#       Created By : Uma M Katru
#       Date : 07-08-2010
#——————————————————————-
dbstartUsage()
{
printf “\nError: $Me – incorrect number of arguments!\n\n”
printf “Usage: $Me <ora sid> [open | mount ].\n\n”
printf “where:\n\n”
printf ”  <ora sid>   : is the unique oracle instance identifier to shutdown non rac and rac instance on the local node required.\n”
printf ”   [<shutdown type>]      : startup type (Valid start up arguments are:  open,mount.\n”
printf “examples:\n”
printf ”  $Me oradv1  — startup database and open\n”
printf ”  $Me oradv1 mount — Starting an Instance and Mounting a Database\n”
exit 1
}
#—————————————————————————-
#Check init or file for the given database instance
#—————————————————————————-
dbstartCheckinitora(){
#check spfile first
spfile=$ORACLE_HOME/dbs/spfile$ORACLE_SID.ora
spfileexists=NO
fileexists=NO
pfile=$ORACLE_HOME/dbs/init$ORACLE_SID.ora
if [[ -f $spfile ]];then
spfileexists=YES
elif [[ -f $pfile ]];then
pfileexists=YES
else
echo “neither spfile nor pfile exists to start $ORACLE_SID database instance”
echo “Please check the issue and restart the process”
upLog “$Me aborted @$(\date)”
exit 1
fi
}
#############################################################################
# write log entries
# $1 is the actual message to log
# —————————————————————————–
upLog()
{
\echo “$1”
}
# —————————————————————————–
# main
#—————————————————————————–
Me=$(\basename $0)
mypath=$(\dirname $0)
export ORACLE_BASE=/u01/app/oracle
#set -vx

args=$#
if [[ $args = 1 ]]; then
ORACLE_SID=$1
STARTMODE=open
elif [[ $args = 2 ]];then
ORACLE_SID=$1
STARTMODE=$2
else
dbstartUsage
fi

#check sid exists in oratab
sidexists=$(grep -i “^$ORACLE_SID:” /etc/oratab |wc -l | awk ‘{print $1}’)
if [[ $sidexists -eq 1 ]];then
echo
ORACLE_HOME=$(grep -w ^”$ORACLE_SID” /etc/oratab | awk -F”:” ‘{print $2}’)
else
echo “oracle instance is not available  on this machine”
exit 1
fi
#Check spfile exists
export ORACLE_SID=$ORACLE_SID
export ORACLE_HOME=$ORACLE_HOME
upLog “$Me started @$(\date)”
upLog “ORACLE_BASE ………………:$ORACLE_BASE”
upLog “ORACLE_HOME ………………:$ORACLE_HOME”
upLog “DB_NAME ………………….:$ORACLE_SID”
dbstartCheckinitora

#Check if db is running or not
ChekDBRunning=`ps -ef | grep -v grep | grep ora_.*_${ORACLE_SID} | wc -l`
if [ $ChekDBRunning -lt 1 ]; then
echo “Info: Database $ORACLE_SID is not up,we can safely start the database .”
else
echo “$ORACLE_SID is already up and running,we can startup shutdown databases only”
exit 0
fi
LogDir=/home/oracle/admin/logs/$ORACLE_SID
if [[ ! -d /home/oracle/admin/logs/$ORACLE_SID ]];then
mkdir -p /home/oracle/admin/logs/$ORACLE_SID
fi
logFile=$LogDir/$(\echo $Me | \awk -F. ‘{print $1}’)$ORACLE_SID.blog.$(\date +%Y%m%d)

echo “Starting up $ORACLE_SID … Please wait…”
$ORACLE_HOME/bin/sqlplus “/ as sysdba”  << ! >> $logFile
startup $STARTMODE
exit
!
if [[ $rc -eq 0 ]] ; then
echo “”
echo “$Me: Database $ORACLE_SID started successfully.”
echo “$Me: Check $logFile logfile for complete details”
upLog “$Me finished @$(\date)”
echo “”
else
echo “”
echo “$Me: unable to startup $ORACLE_SID database instance,Please see log file for details.”
echo “$Me: Check $logFile logfile for complete details”
upLog “$Me failed to start $ORACLE_SID @$(\date)”
exit 1
fi
echo “—————————————————————-” >> $logFile
exit 0

 

Error: orastartdb.ksh – incorrect number of arguments!

Usage: orastartdb.ksh <ora sid> [open | mount ].

where:

<ora sid>   : is the unique oracle instance identifier to shutdown non rac and rac instance on the local node required.
[<shutdown type>]      : startup type (Valid start up arguments are:  open,mount.
examples:
orastartdb.ksh oradv1  — startup database and open
orastartdb.ksh oradv1 mount — Starting an Instance and Mounting a Database

 

====entry exisis in oratab but pfile or spfile is missing

./orastartdb.ksh uk10204

orastartdb.ksh started @Mon Jul 11 12:25:55 PDT 2011
ORACLE_BASE ………………:/u01/app/oracle
ORACLE_HOME ………………:/u01/app/oracle/product/10.2.0.5/db_1
DB_NAME ………………….:uk10204
neither spfile nor pfile exists to start uk10204 database instance
Please check the issue and restart the process
orastartdb.ksh aborted @Mon Jul 11 12:25:55 PDT 2011

======

./orastartdb.ksh uk10205

orastartdb.ksh started @Mon Jul 11 12:26:11 PDT 2011
ORACLE_BASE ………………:/u01/app/oracle
ORACLE_HOME ………………:/u01/app/oracle/product/10.2.0.5/db_1
DB_NAME ………………….:uk10205
Info: Database uk10205 is not up,we can safely start the database .
Starting up uk10205 … Please wait…

orastartdb.ksh: Database uk10205 started successfully.
orastartdb.ksh: Check /home/oracle/admin/logs/uk10205/orastartdbuk10205.blog.20110711 logfile for complete details
orastartdb.ksh finished @Mon Jul 11 12:26:29 PDT 2011

=====

./orastartdb.ksh uk10205

orastartdb.ksh started @Mon Jul 11 12:27:00 PDT 2011
ORACLE_BASE ………………:/u01/app/oracle
ORACLE_HOME ………………:/u01/app/oracle/product/10.2.0.5/db_1
DB_NAME ………………….:uk10205
uk10205 is already up and running,we can startup shutdown databases only

 

Thanks

Categories: dba_scripts
  1. No comments yet.
  1. No trackbacks yet.

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: