Instance Startup and Shutdown
LeasePak Documentation Suite NETSOL website
Oracle 19c Server

Oracle 19c Server

Instance Startup and Shutdown

Automatic Startup and Shutdown of Oracle Instance and Listener

To configure the DBMS host to automatically shutdown and startup the Oracle instance and listener when the operating system is rebooted:

  1. Log on the DBMS host as the Oracle software owner.
  2. Create a directory named startup by entering at the Unix prompt:
    # mkdir /home/oracle/startup
  3. Create a Unix script named /home/oracle/startup/ora_startup_shutdown.sh. Sample code for the ora_startup_shutdown.sh script is provided in the next section.
  4. Set permissions on the ora_startup_shutdown.sh script by entering at the Unix prompt:
    # chmod 0744 /home/oracle/startup/ora_startup_shutdown.sh
  5. Log on the DBMS host as the root user.
  6. Create a systemd unit file named /etc/systemd/system/oracle.service. Using a text editor, enter the following lines into the oracle.service file:
    [Unit]
    Description=Oracle Database and Listener
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/home/oracle/startup/ora_startup_shutdown.sh start
    ExecStop=/home/oracle/startup/ora_startup_shutdown.sh stop
    User=oracle
    WorkingDirectory=/home/oracle
    LimitNOFILE=65536
    LimitMEMLOCK=infinity
    
    [Install]
    WantedBy=multi-user.target
    

    Note: Since systemd ignores /etc/security/limits.conf and /etc/security/limits.d, some of the resource limits from /etc/security/limits.d/oracle-database-preinstall-19c.conf must be specified manually in the oracle.service unit file. The resource limits to manually specify are those where the Oracle value in the oracle-database-preinstall-19c.conf configuration file is greater than the Unix default value. For Oracle 19c, manually specify LimitNOFILE and LimitMEMLOCK in oracle.service.

  7. Set permissions on the oracle.service unit file by entering at the Unix prompt:
    # chmod 0644 /etc/systemd/system/oracle.service
  8. Load the oracle.service unit file by entering at the Unix prompt:
    # systemctl daemon-reload
  9. Configure Oracle to automatically shutdown and startup when the operating system is rebooted by entering at the Unix prompt:
    # systemctl enable oracle

A log of Oracle startups and shutdowns is written by the ora_startup_shutdown.sh script to the /home/oracle/startup/startup_shutdown.log file. The startup_shutdown.log file logs Oracle startups and shutdowns that occur automatically when the operating system is rebooted, as well as manual startups and shutdowns performed with the systemctl command. Oracle startups and shutdowns performed manually with sqlplus are not logged in startup_shutdown.log.

Sample code for ora_startup_shutdown.sh script

#!/bin/sh
#-------------------------------------------------------------------------------------------------
# File        : ora_startup_shutdown.sh
# Description : unix script to start or stop Oracle instance and listener
# Parameter   : $1 - "start" or "stop"
# Caller      : usually called by systemd oracle.service unit file
#-------------------------------------------------------------------------------------------------
# This script appends its standard output and standard error to log file startup_shutdown.log
# in directory /home/oracle/startup
#-------------------------------------------------------------------------------------------------
option=$1
umask 022
export LANG=C
export LC_ALL=C
export NLS_LANG=American_America.WE8ISO8859P1
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
exec >> /home/oracle/startup/startup_shutdown.log 2>&1
echo
echo "----------------------------------------------------------------------------"
echo
echo "ora_startup_shutdown.sh called at `date '+%F %T'` with option '$option'"

if [ "$option" = start ]; then
        echo "Starting listener..."
        lsnrctl start
        if [ $? -ne 0 ]; then
                echo "Unable to start listener"
                exit 1
        fi
        echo
        echo "Starting instance '$ORACLE_SID'..."
        sqlplus / as sysdba <<EOHD
        startup
        exit
EOHD
elif [ "$option" = stop ]; then
        echo "Stopping listener..."
        lsnrctl stop
        if [ $? -ne 0 ]; then
                echo "Unable to stop listener"
                exit 1
        fi
        echo
        echo "Stopping instance '$ORACLE_SID'..."
        sqlplus / as sysdba <<EOHD
        shutdown immediate
        exit
EOHD
else
        echo
        echo "ora_startup_shutdown.sh: invalid option parameter '$option'"
        exit 1
fi
echo
echo "ora_startup_shutdown.sh: end `date '+%F %T'`"
exit 0

Manual Startup of Oracle Instance and Listener

If the oracle.service unit file has been installed:

  1. Log on the DBMS host as the root user.
  2. Enter at the Unix prompt:
    # systemctl start oracle

If the oracle.service unit file has not been installed:

  1. Log on the DBMS host as the Oracle software owner.
  2. Start the listener by entering at the Unix prompt:
  3. % lsnrctl start
  4. Enter at the Unix prompt:
    % sqlplus / as sysdba
  5. Startup the instance by entering at the sqlplus prompt:
    SQL> startup

Manual Shutdown of Oracle Instance and Listener

If the oracle.service unit file has been installed:

  1. Log on the DBMS host as the root user.
  2. Enter at the Unix prompt:
    # systemctl stop oracle

If the oracle.service unit file has not been installed:

  1. Log on the DBMS host as the Oracle software owner.
  2. Stop the listener by entering at the Unix prompt:
  3. % lsnrctl stop
  4. Enter at the Unix prompt:
    % sqlplus / as sysdba
  5. Change the current container to CDB$ROOT by entering at the sqlplus prompt:
    SQL> alter session set container = CDB$ROOT;
  6. Shutdown the instance:
  7. SQL> shutdown immediate

Manual Bounce (Shutdown and Startup) of Oracle Instance and Listener

If the oracle.service unit file has been installed:

  1. Log on the DBMS host as the root user.
  2. Enter at the Unix prompt:
    # systemctl restart oracle

If the oracle.service unit file has not been installed, refer to the manual shutdown and startup instructions previously listed in this document.

Check Status of Oracle Listener

  1. Log on the DBMS host as the Oracle software owner.
  2. Enter at the Unix prompt:
    % lsnrctl status

Check Status of Oracle Instance

If the oracle.service unit file has been installed:

  1. Log on the DBMS host as either the root user or the Oracle software owner.
  2. Enter at the Unix prompt:
    # systemctl status oracle

If the oracle.service unit file has not been installed:

  1. Log on the DBMS host as the Oracle software owner.
  2. Enter at the Unix prompt:
    % sqlplus / as sysdba
  3. Change the current container to CDB$ROOT by entering at the sqlplus prompt:
    SQL> alter session set container = CDB$ROOT;
  4. Run this command:
  5. SQL> show sga

Automatic Startup of Oracle Pluggable Database (PDB)

To configure a PDB to automatically startup whenever the Oracle instance is started:

  1. Log on the DBMS host as the Oracle software owner.
  2. Enter at the Unix prompt:
    % sqlplus / as sysdba
  3. Change the current container to CDB$ROOT by entering at the sqlplus prompt:
    SQL> alter session set container = CDB$ROOT;
  4. Make sure the PDB is open by running this command:
    SQL> alter pluggable database PDB-name open;
  5. Run this command:
    SQL> alter pluggable database PDB-name SAVE STATE;

Manual Startup of an Oracle PDB

  1. Log on the DBMS host as the Oracle software owner.
  2. Enter at the Unix prompt:
    % sqlplus / as sysdba
  3. Change the current container to CDB$ROOT by entering at the sqlplus prompt:
    SQL> alter session set container = CDB$ROOT;
  4. Startup the PDB:
    SQL> alter pluggable database PDB-name open;

Manual Shutdown of an Oracle PDB

  1. Log on the DBMS host as the Oracle software owner.
  2. Enter at the Unix prompt:
    % sqlplus / as sysdba
  3. Change the current container to CDB$ROOT by entering at the sqlplus prompt:
    SQL> alter session set container = CDB$ROOT;
  4. Shutdown the PDB:
    SQL> alter pluggable database PDB-name close immediate;

Check Status of Oracle Pluggable Databases (PDBs)

  1. Log on the DBMS host as the Oracle software owner.
  2. Enter at the Unix prompt:
    % sqlplus / as sysdba
  3. Change the current container to CDB$ROOT by entering at the sqlplus prompt:
    SQL> alter session set container = CDB$ROOT;
  4. Run this command:
  5. SQL> show pdbs