To configure the DBMS host to automatically shutdown and startup the Oracle instance and listener when the operating system is rebooted:
startup
by entering at the Unix prompt:
# mkdir /home/oracle/startup
/home/oracle/startup/ora_startup_shutdown.sh
.
Sample code for the ora_startup_shutdown.sh
script is provided in the next section.
ora_startup_shutdown.sh
script by entering at the Unix prompt:
# chmod 0744 /home/oracle/startup/ora_startup_shutdown.sh
root
user./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.
oracle.service
unit file by entering at the Unix prompt:
# chmod 0644 /etc/systemd/system/oracle.service
oracle.service
unit file by entering at the Unix prompt:
# systemctl daemon-reload
# 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
.
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
If the oracle.service unit file has been installed:
root
user.# systemctl start oracle
If the oracle.service unit file has not been installed:
% lsnrctl start
% sqlplus / as sysdba
SQL> startup
If the oracle.service unit file has been installed:
root
user.# systemctl stop oracle
If the oracle.service unit file has not been installed:
% lsnrctl stop
% sqlplus / as sysdba
SQL> alter session set container = CDB$ROOT;
SQL> shutdown immediate
If the oracle.service unit file has been installed:
root
user.# 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.
% lsnrctl status
If the oracle.service unit file has been installed:
root
user or the Oracle software owner.# systemctl status oracle
If the oracle.service unit file has not been installed:
% sqlplus / as sysdba
SQL> alter session set container = CDB$ROOT;
SQL> show sga
To configure a PDB to automatically startup whenever the Oracle instance is started:
% sqlplus / as sysdba
SQL> alter session set container = CDB$ROOT;
SQL> alter pluggable database PDB-name open;
SQL> alter pluggable database PDB-name SAVE STATE;
% sqlplus / as sysdba
SQL> alter session set container = CDB$ROOT;
SQL> alter pluggable database PDB-name open;
% sqlplus / as sysdba
SQL> alter session set container = CDB$ROOT;
SQL> alter pluggable database PDB-name close immediate;
% sqlplus / as sysdba
SQL> alter session set container = CDB$ROOT;
SQL> show pdbs