Oracle database status, start, stop
Manual operation
[oracle@aixdb01]/home/oracle> sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Fri Sep 4 13:18:29 2015
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
SQL> select status from v$instance;
STATUS
------------
STARTED
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 8551575552 bytes
Fixed Size 2236744 bytes
Variable Size 4429188792 bytes
Database Buffers 4093640704 bytes
Redo Buffers 26509312 bytes
Script to start and stop
# cat /etc/rc.d/init.d/oracledb
#!/bin/ksh
# Start and Stop oracle and the listener
USER=oracle
PATH1=${PATH}
SQLDBA="sqlplus /nolog"
ORATAB=/etc/oratab
ulimit -c unlimited
ulimit -d unlimited
ulimit -s unlimited
if [ ! -f $ORATAB ]
then
echo "ERROR file $ORATAB doesn't exists"
exit 1
fi
StartService()
{
echo "Starting Oracle databases"
su $USER -c "$SQLDBA $args <<EOF
connect / as sysdba
startup
quit
EOF"
if [ $(ps -ef | grep "$ORACLE_HOME/bin/tnslsnr | grep -v grep > /dev/null;echo $?) -ne 0 ]
then
echo "Starting Oracle LISTENER"
su - $USER -c "$ORACLE_HOME/bin/lsnrctl start"
fi
}
StopService()
{
if [ $(ps -ef | grep "$ORACLE_HOME/bin/tnslsnr | grep -v grep > /dev/null;echo $?) -eq 0 ]
then
echo "Stopping Oracle LISTENER"
su - $USER -c "$ORACLE_HOME/bin/lsnrctl stop"
fi
echo "Stopping Oracle databases"
su $USER -c "$SQLDBA $args <<EOF
connect / as sysdba
shutdown immediate
quit
EOF"
}
cat "$1" in
start ) for line in $(cat /etc/oratab | grep -v '^#' | sed '/^$/d')
do
ORACLE_SID=$(echo $line | cut -d':' -f1)
ORACLE_HOME=$(echo $line | cut -d':' -f2)
echo "************************************"
echo "* Starting Database : $ORACLE_SID *"
echo "************************************"
PATH=${PATH1}:$ORACLE_HOME/bin
export ORACLE_SID ORACLE_HOME PATH
pmon=$(ps -ef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep)
if [ "$pmon" != "" ]
then
echo "Warning: the database $ORACLE_SID is still started"
else
StartService
fi
done
;;
stop ) for line in $(cat /etc/oratab | grep -v '^#' | sed '/^$/d')
do
ORACLE_SID=$(echo $line | cut -d':' -f1)
ORACLE_HOME=$(echo $line | cut -d':' -f2)
echo "************************************"
echo "* Stopping Database : $ORACLE_SID *"
echo "************************************"
PATH=${PATH1}:$ORACLE_HOME/bin
export ORACLE_SID ORACLE_HOME PATH
pmon=$(ps -ef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep)
if [ "$pmon" != "" ]
then
StopService
else
echo "Warning: the database $ORACLE_SID is still stopped"
fi
done
;;
status ) for line in $(cat /etc/oratab | grep -v '^#' | sed '/^$/d')
do
ORACLE_SID=$(echo $line | cut -d':' -f1)
ORACLE_HOME=$(echo $line | cut -d':' -f2)
PATH=${PATH1}:$ORACLE_HOME/bin
export ORACLE_SID ORACLE_HOME PATH
pmon=$(ps -ef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep)
if [ "$pmon" != "" ]
then
echo "DB $ORACLE_SID is started OK"
else
echo "DB $ORACLE_SID is stopped"
fi
if [ $(ps -ef | grep "$ORACLE_HOME/bin/tnslsnr | grep -v grep > /dev/null;echo $?) -eq 0 ]
then
echo "Listener is started OK"
else
echo "no Listener for this DB
fi
done
;;
* ) echo "Usage: $0 (start | stop | status)"
exit 1
esac