• 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

Navigation

  • Glossary
  • Recent posts

Search

User login

  • Request new password

Recent comments

  • On the same port
    8 weeks 5 days ago
  • All, with 2 daemons running
    12 weeks 23 hours ago
  • /etc/init.d/sshd
    16 weeks 2 days ago
  • No easy way to do this
    16 weeks 2 days ago
  • external iface is dhcpd addressed
    16 weeks 3 days ago
  • Great
    18 weeks 4 days ago
  • Great!
    21 weeks 4 days ago
  • Thanks!
    23 weeks 2 days ago
  • keyboard-interactive?
    23 weeks 2 days ago
  • no authentication method
    23 weeks 3 days ago

Use Free Software!

Visit the Free Software Directory

Baanboard.com

  • NEW: added forum and moderator for Russian users!
  • Archiving Localized Data
  • Baan IV and ERP LN Tools Consultant
  • Provide application design and development expertise in Baan IVC4.
  • Purchase order - Exctracting prices
more

UNIX.com

  • Equivalent of /etc/rc.local in Solaris 10
  • RAMDISK: EOF while reading compressed data ...Kernel panic - Unable to mount root
  • Python3 bytearray padding
  • iptables rule problem
  • Perl: Extracting a char from a string.
more

  • home
  • contact
  • services
  • baanboard
  • msx