Wednesday, February 10, 2021

How to Start and Stop Oracle Database and Listener Automatically with Server Reboot

 

 

How to Start and Stop Oracle Database and Listener Automatically  with Server Reboot

In this post, I am going to share how the Oracle database and listener can automatically
shutdown and startup when the server reboots.
I have a 19c  Database 


Steps:

1) Edit the /etc/oratab file, and place a Y at the end of the entry for the databases you want to
 automatically restart when the system reboots. 

# vi /etc/oratab
[SID]:[ORACLE_HOME]:Y
GOLD19:/u01/19cDB:Y

The Y on the end of the string signifies that the database can be started and stopped by the
 ORACLE_HOME/bin/dbstart and ORACLE_HOME/bin/dbshut scripts.


2) Create the service script /etc/init.d/dbora. The content of the script is as follows. Make sure you change the values of variables ORA_HOME and ORA_OWNER to match your environment.

All is being done via root user.

#!/bin/bash
# chkconfig: 35 99 10
# description: Starts and Stops Oracle and Listener processes
ORACLE_HOME=/u01/19cDB
ORA_OWNER=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH
case "$1" in
  'start')
        echo -n $"Starting Oracle DB: "
    su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" &
    su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &
   ;;
  'stop')
        echo -n $"Shutting down Oracle DB: "
    su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" &
    su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &
;;
'restart')
        echo -n $"Shutting down Oracle DB: "
          su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" &
          su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &
        sleep 5
        echo -n $"Starting Oracle DB: "
        su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" &
        su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &
  ;;      
*)
        echo "usage: $0 {start|stop|restart}"
        exit

   ;;
esac

# End of script dbora




# chkconfig: 35 99 10
# description: Starts and stops Oracle database
The above are mandatory and not just comments since they describe the characteristics of the
 service where:

    • 35-means that the service will be started in init levels 3 and 5 and will be stopped in other
 levels.

    • 99-means that the service will be started at the near end of the init level processing

    • 10-means that the service will be stopped at the near beginning of the init level processing


3) Make the script executable and Enable to run on boot

1. Change the group of the dbora file to match the group assigned to the operating system owner of the Oracle software 

# chgrp dba /etc/init.d/dbora

2. Set the script permissions to 755

# chmod 750 /etc/init.d/dbora

3. Run the following chkconfig command:

# chkconfig --add dbora

This action registers the service to the Linux service mechanism. This also creates the appropriate symbolic links to files beneath the /etc/rc.d directory. 

[root@fundb rc.d]# cd rc3.d
[root@fundb rc3.d]# ls -ltr
total 0
lrwxrwxrwx. 1 root root 17 Jan 26 13:49 S10network -> ../init.d/network
lrwxrwxrwx. 1 root root 20 Jan 26 13:49 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 15 Jan 26 13:55 S97rhnsd -> ../init.d/rhnsd
lrwxrwxrwx. 1 root root 15 Feb 10 17:01 S99dbora -> ../init.d/dbora

Use the –list option to display whether a service is on or off for each run level:

# chkconfig --list | grep dbora
dbora           0:off   1:off   2:off   3:on    4:off   5:on    6:off

If you need to delete a service, use the --del option of chkconfig.

On Linux 7:

# systemctl enable dbora
/sbin/chkconfig dbora on


Thats it, lets reboot server and validate
You can also do

service dbora stop
service dbora start

On Oracle Database Multitenant PDBs 12c/18c/19c we can create a trigger to start all PDB’s after the restart

Run the following pl/sql with SYSDBA

create or replace trigger sys.after_startup
   after startup on database
begin
   execute immediate 'alter pluggable database all open';
end after_startup;
/

 

 

 This is to troubleshoot the website working from remote desktop

Run these in PowerShell from the machine having the problem:

Test-NetConnection finprodapp.abcd.edu -Port 443


Invoke-WebRequest https://finprodapp.abcd.edu/ 




Check from Server SSL, TSL connectivity :


openssl s_client -connect finesupgd.abcd,edu:443 -tls1_2