Problem solve Get help with specific problems with your technologies, process and projects.

Check for Oracle availability and tablespace capacity

A script that will check if all of Oracle instances are up and if any of the tablespaces are running short of freespace.

Checking Oracle for availability requires more than just a ping or a 'ps -ef | grep oracle' command. I believe it requires a test accessing Oracle using SQL*Net to verify that the listener is also up and running -- this would be the access that a user would normally use. By actually logging on to the instance, you verify that the instance will accept logins whereas if you only do the above checks, how would you know if logins are not accepted due to archiver log waits?

Along with Oracle being alive and accessible, I also check to make sure it can be used, so I also check for tabalespace capacity.

I have written a few scripts that allows me to check:

  1. if all of the Oracle instances are up
  2. if any of the extents have reached their maximum limit
  3. if any of the tablespaces are running short of freespace

The script can be run from crontab with any interval you feel comfortable with. This script will also page or email the support personnel when any of the above exceptions are met.

If there are any other tests that you would like to do, this script can be easily modified to include them. I use this Monitororcl script as a template and just add functionality at the end.

The script that is called from crontab:

 #!/bin/ksh . /u01/home/oracle/.profile /u01/app/oracle/admin/monitororcl 'cat /u01/app/oracle/admin/Get_Oracle_Instance_List' exit

The Get_Oracle_Instance_List script:

 instance_name1 tnsname1 sys_password_for_this_instance instance_name2 tnsname2 sys_password_for_this_instance instance_name3 tnsname3 sys_password_for_this_instance

Here is the MONITORORCL script:

 #!/bin/ksh #script : Rick Stehno # script will monitor to see if Oracle is up while [ "$1" != "" ] do ORACLE_INSTANCE=$1 ORACLE_TNS=$2 USR_ID=sys USR_PASS=$3 # echo "Instance: [$ORACLE_INSTANCE]" # echo "TNS [$ORACLE_TNS]" # echo "PASS: [$USR_PASS]" LOGFIL=/u01/app/oracle/admin/monitordev1.out,userid2, # # check for critical segments are not reaching maxextents # sqlplus -s <<EOF1 >$LOGFIL 2>/dev/null $USR_ID/$USR_PASS@$ORACLE_TNS set pages 0 select distinct 'YES' from dba_segments where extents >= (max_extents-5) and segment_name not like '1.%'; EOF1 grep -i '^ORA-' $LOGFIL >/dev/null if [ $? -eq 0 ] then echo "$0 failed: check $ORACLE_INSTANCE for problems" | /bin/mailx -s "${ORACLE_INSTANCE} : Script failed" $NOTIFY_LIST exit 1 fi MAXEXTENTS_REACHED=`awk '{ print $1 }' $LOGFIL` if [ "$MAXEXTENTS_REACHED" = "YES" ] then echo "$0 failed: $ORACLE_INSTANCE max extents reached" | /bin/mailx -s "${ORACLE_INSTANCE} : max extents reached" $NOTIFY_LIST exit 1 fi # # check for unable to allocate next segment # sqlplus -s <<EOF2 >$LOGFIL 2>/dev/null $USR_ID/$USR_PASS@$ORACLE_TNS set pages 0 select distinct 'YES' from dba_segments ds where next_extent > (select max(bytes) from dba_free_space where tablespace_name = ds.tablespace_name); EOF2 grep -i '^ORA-' $LOGFIL >/dev/null if [ $? -eq 0 ] then echo "$0 failed: check $ORACLE_INSTANCE for problems" | /bin/mailx -s "${ORACLE_INSTANCE} : Script failed" $NOTIFY_LIST exit 1 fi POSSIBLE_NEXTEXT_FAIL=`awk '{print $1 }' $LOGFIL` if [ "$POSSIBLE_NEXTEXT_FAIL" = "YES" ] then echo "$0 failed: $ORACLE_INSTANCE cannot extend segment" | /bin/mailx -s "${ORACLE_INSTANCE} : max extents reached" $NOTIFY_LIST exit 1 fi shift 3 # echo "shift done" done echo "Successful completion of $0" `date` exit 0


For More Information

  • What do you think about this tip? E-mail us at with your feedback.
  • The Best Oracle Web Links: tips, tutorials, scripts, and more.
  • Have an Oracle tip to offer your fellow DBA's? The best tips submitted will receive a cool prize--submit your tip today!
  • Ask your technical Oracle questions--or help out your peers by answering them--in our live discussion forums.
  • Check out our Ask the Experts feature: Our SQL, Database Design, Oracle, SQL Server, DB@, metadata, and datawarehousing gurus are waiting to answer your toughest questions.

Dig Deeper on Oracle database availability

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.