• ALGEMENE VOORWAARDEN
  • GENERAL TERMS & CONDITIONS

KUDOS - IT consultant and FOSS supporter

  • home
  • contact
  • services
  • baanboard
  • for sale
  • 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
  • del.icio.us del.icio.us
  • Digg Digg
  • Facebook Facebook
  • Google Google
  • identi.ca identi.ca
  • LinkedIn LinkedIn
  • Ping This! Ping This!
  • Reddit Reddit
  • StumbleUpon StumbleUpon
  • Technorati Technorati
  • Twitter Twitter
  • Yahoo Yahoo
  • Add new comment

Navigation

  • Glossary
  • Recent posts

Search

User login

  • Request new password

Recent comments

  • Great Command
    4 weeks 1 day ago
  • "Match" sshd_config keyword, an alternative?
    22 weeks 2 days ago
  • startup
    1 year 16 weeks ago
  • sweet
    1 year 16 weeks ago
  • On the same port
    1 year 35 weeks ago
  • All, with 2 daemons running
    1 year 39 weeks ago
  • /etc/init.d/sshd
    1 year 43 weeks ago
  • No easy way to do this
    1 year 43 weeks ago
  • external iface is dhcpd addressed
    1 year 43 weeks ago
  • Great
    1 year 45 weeks ago

Use Free Software!

Visit the Free Software Directory

Baanboard.com

  • Validating a field value with no Standard Script
  • How I can Access ERP LN 6.1 through .NET
  • Calling Standard ERP Maintain Session in read only mode
  • Infor Report Studio (Birt) with Oracle DB
  • SLM Time Out
more

  • home
  • contact
  • services
  • baanboard
  • for sale
  • msx