oracledba.help
System

Database (start,stop, status)

Prerequisites

  • Oracle has been installed and database created.
  • Oracle environment set for database instance to control.
    • LINUX\UNIX
      OS> set ORACLE_SID=<InstanceName>
      OS> set ORACLE_HOME=<OracleHomePath>
      OS> sqlplus sys/<Password> as sysdba
      SQLPlus> <shutdown immediate|startup>
    
    • Windows 12c Services
      Net <Start|Stop> OracleService{SID}
      Net <Start|Stop> OracleJobScheduler{SID} (If used)
      Net <Start|Stop> OracleMTSRecoveryService (Oracle 11g)
      Net <Start|Stop> OracleOraDB12gHome1TNSListener
    
    Other services that may be initially active include:
      OracleDBConsole{SID}, OracleOraDbnng_home1ClrAgent, 
      OracleRemExecServiceV2, OracleVSSWriter{SID}
    

Display

-- Display Database Status

SELECT d.dbid,i.instance_name,i.host_name,d.open_mode,
       d.database_role,i.status,i.database_status,
       to_char(i.startup_time,'YYYY-MM-DD HH:MM') AS "Started",
       d.log_mode, i.archiver,i.version
FROM v$database d, v$instance i
WHERE UPPER(d.name) = UPPER(i.instance_name);

Start

LINUX\UNIX

OS> sqlplus sys/******** as sysdba
SQLPLUS> startup

Windows

C:\> Net Start OracleServiceDB01
C:\> Net Start OracleJobSchedulerDB01 (If used)
C:\> Net Start OracleOraDB12gHome1TNSListener

Note: The OracleService{SID} issues a STARTUP command in the background.

Stop

LINUX\UNIX

OS> sqlplus sys/******** as sysdba
SQLPLUS> shutdown immediate

Windows

C:\> Net Stop OracleOraDB12gHome1TNSListener
C:\> Net Stop OracleJobSchedulerDB01 (If used)
C:\> Net Stop OracleServiceDB01

Note: The OracleService{SID} issues a SHUTDOWN IMMEDIATE command in the background.

Database Start on Linux OS Boot

Create a dbora script to start and stop your database.

For a dedicated standalone Data Guard StandBy database simply edit the $ORACLE_HOME/bin/dbstart script and change startup command to startup mount.

Example, change this (1):

 "6")  sqldba command=startup ;;

To This

 "6")  sqldba command=startup mount ;;

Assumptions:

  • Password has not been set for the Oracle Net listener.
  • The listener name is LISTENER. If not then you have to specify stop and start commands for it.
    Ex: $ORACLE_HOME/bin/lsnrctl {start|stop} listener_name

vi /etc/init.d/dbora

#!/bin/sh
#
# Implementation:
# 1. Edit the /etc/oratab
#    Ex: oradb:/u01/app/oracle/product/12.2.0.1/dbhome_1:Y 
# 2. As root, create this file as /etc/init.d/dbora then:
#    chgrp dba /etc/init.d/dbora
#    chmod 750 /etc/init.d/dbora
# 3. Create links
#    ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
#    ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
#    ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora

#ORA_HOME=/u01/app/oracle/product/12.2.0.1/dbhome_1
#ORA_HOME=/u01/app/oracle/product/19.3.0.0.0/dbhome_1
ORA_HOME=/u01/app/oracle/product/21.3.0.0.0/dbhome_1
ORA_OWNER=oracle 

if [ ! -f $ORA_HOME/bin/dbstart ]
then 
   echo "Oracle startup: cannot start"
   exit
fi

case "$1" in
   'start')
     su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" 
     touch /var/lock/subsys/dbora
     ;;
   'stop')
     su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME" 
     rm -f /var/lock/subsys/dbora
     ;;
esac

Cheat Sheet Cmds To Enable

 chgrp dba /etc/init.d/dbora; chmod 750 /etc/init.d/dbora; ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
 ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora; ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora

<- System