Skip to content
Home » Oracle Database » How to Check if Oracle Database is Running

How to Check if Oracle Database is Running

To make sure that an Oracle database is alive, we can use a piece of shell script to check it.

[oracle@test ~]$ vi check_database_alive.sh
#!/bin/bash
. ~/.bash_profile

ps -ef | grep "ora_smon_$ORACLE_SID" | grep -v grep > /dev/null
if [ $? -eq 0 ]; then
        echo "Database $ORACLE_SID is alive!"
else
        echo "Database $ORACLE_SID is dead!"
fi

The key is that we check the existence of the system monitor process (SMON) to determine the result in the above code.

To make it executable, we add execution permissin on user.

[oracle@test ~]$ chmod u+x check_database_alive.sh

Let's test the script when the database is running.

[oracle@test ~]$ ./check_database_alive.sh
Database ORCLCDB is alive!

What if the database is idle? Let's see what the result will be.

[oracle@test ~]$ ./check_database_alive.sh
Database ORCLCDB is dead!

For a different ORACLE_SID, you may use oraenv to set the variable before checking.

The drawback of the script is that, it always returns a positive result as long as the instance is running, no matter what state it is. That is to say, a NOMOUNT database is also determined as being alive.

For further investigation, you may need a script to check the database status.

Leave a Reply

Your email address will not be published. Required fields are marked *