• ALGEMENE VOORWAARDEN
  • GENERAL TERMS & CONDITIONS

KUDOS - IT consultant and FOSS supporter

  • home
  • contact
  • services
  • baanboard
  • msx
Home

Shutting down Oracle databases quickly in parallel

patvdv's picture

patvdv — Mon, 27/07/2009 - 19:08

Most folks running a larger(r) amount of Oracle instances on the one and same server use a sequential method for shutting down their databases at for example backup time or during system shutdown. This can pose some inconveniences and at worst a real problem if it takes a long while before these SHUTDOWN IMMEDIATE commands complete. A concrete example may be the requirement to quickly shutdown your system during a power failure whilst still running on UPS batteries.

To work around this issue I have made a small script that can be used to shutdown a whole bunch of databases in a much faster but yet still tidy fashion. This is archieved by running all database shutdown in parallel and in the background using a helper script and the nohup facility.

Here's what the code of the main shutdb_all.ksh script looks like:

#!/usr/bin/ksh
print "Database(s) shutdown starting"
for ORA_DB in ${MY_DB_LIST}
do
    # shutdown databases in parallel
    print "Shutting down database ${ORA_DB} in the background ..." 
    nohup ~oracle/shutdb.sh ${ORA_DB} &
done

# check status of shutdown child processes
SHUTDB_ACTIVE=$(pgrep -f "shutdb" | wc -l | tr -d '[[:space:]]')
COUNTER=0
while [[ ${SHUTDB_ACTIVE} -gt 0 ]]
do
    print "Shutdown of database(s) is still ongoing (${SHUTDB_ACTIVE} processes running) ..."
    sleep 20
    SHUTDB_ACTIVE=$(pgrep -f "dbshut" | wc -l | tr -d '[[:space:]]')
    COUNTER=$((COUNTER + 1))
    if [[ ${COUNTER} -eq 12 ]]
    then
        print "Databases are still not shutdown after $((COUNTER  \* 20)) seconds."
        print "*PLEASE CHECK!* Continuing with the rest of the script!"
        break
    fi
done
print "Database(s) shutdown finished"

Configure the $MY_DB_LIST variable with the names of your Oracle database instances, for example:

MY_DB_LIST="db1 db2 db3 db4"

The above script will also need a helper script called shutdb.sh whose primary task it is to shutdown a single database instance. This helper script may look something like this and should go into the HOME directory of the oracle user:

#!/usr/bin/ksh
ORAENV_ASK="NO"
ORACLE_SID="$1"
EXEC_DBA="sqlplus /nolog"

. oraenv

# check for database online
STATUS=$(ps -fu oracle | grep -w "ora_[a-z]*_${ORACLE_SID}")
if [[ $? -eq 0 ]]
then
    # database is down
    print "Database is already down. Continuing."
else
    # database is up
    echo "Shutting down immediate."
    $EXEC_DBA </dev/null >>EOS
    connect /as sysdba
    alter system switch logfile;
    shutdown immediate;
    exit
EOS
    STATUS=$(ps -fu oracle | grep -w "ora_[a-z]*_${ORACLE_SID}" )
    if [[ $? -eq 0 ]]
    then
        print "Error in database shutdown. Exiting."
        exit 1
    fi
fi
exit 0

Note that the shutdb_all.ksh script is meant to run on Linux/Solaris platforms as it depends on the pgrep utiliity. For sure, the script can be made more generic to suit more Unix flavours but in my case, Solaris was the only platform to support.

Bookmark/Search this post with:
  • Delicious Delicious
  • Digg Digg
  • StumbleUpon StumbleUpon
  • Propeller Propeller
  • Reddit Reddit
  • Magnoliacom Magnoliacom
  • Google Google
  • Yahoo Yahoo
  • Technorati Technorati
  • Add new comment

respond this topic

Anonymous — Fri, 12/03/2010 - 12:04

I’ll tell my friends about your supreme thing relating with article. I look through your buy paper close to article. Therefore, at this wonderful moment I take custom papers or custom written essay I really needed. Thank you so much!

  • reply

Navigation

  • Glossary
  • Recent posts

Search

User login

  • Request new password

Recent comments

  • re
    1 day 1 hour ago
  • respond this topic
    2 days 10 hours ago
  • Great!
    1 week 5 days ago
  • Thanks!
    3 weeks 3 days ago
  • keyboard-interactive?
    3 weeks 3 days ago
  • no authentication method
    3 weeks 4 days ago
  • nicely written
    3 weeks 4 days ago
  • Awesome! Thank you!
    10 weeks 3 days ago
  • Excellent script
    10 weeks 3 days ago
  • Not corrupt but wrong file extension
    41 weeks 4 days ago

Use Free Software!

Visit the Free Software Directory

Baanboard.com

  • Baan Finance Support consultant (Mid Level)
  • Baan Logistic Consultant, with 5 year experience in Baan IV, SP0, FP2.
  • Determine the domain of a field (Baan IV)
  • How to get day difference between 2 dates?
  • ntbshell response very slow from command line
more

UNIX.com

  • count words and empty files
  • Help with pattern matching
  • Using grep to extract PID
  • Help with for loops
  • common contents of two files
more

  • home
  • contact
  • services
  • baanboard
  • msx