Database Auto Startup in oracle 19c


Follow the Steps below to enable auto startup of DB instance , Listener and PDB's

1. Create dbora file as below with ORACLE_HOME


[root@oraclesrv ~]# cat /etc/init.d/dbora
#! /bin/sh -x
#
# chkconfig: 2345 80 05
# description: start and stop Oracle Database Enterprise Edition on Oracle Linux 5 and 6
#
# In /etc/oratab, change the autostart field from N to Y for any
# databases that you want autostarted.
#
# Create this file as /etc/init.d/dbora and execute:
#  chmod 750 /etc/init.d/dbora
#  chkconfig --add dbora
#  chkconfig dbora on
# Note: Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for your installation.
# ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
ORACLE_HOME=/u01/app/oracle/db1
#
# Note: Change the value of ORACLE to the login name of the oracle owner
ORACLE=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH
case $1 in
'status')
       echo -n $"Oracle Process: "
      su $ORACLE -c "ps -ef | grep pmon | grep -v grep; ps -ef | grep -i listener | grep -v grep;" &
        ;;
'start')
       echo -n $"Starting Oracle: "
      su $ORACLE -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &
        ;;
'stop')
       echo -n $"Shutting down Oracle: "
       su $ORACLE -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &
        ;;
'restart')
       echo -n $"Shutting down Oracle: "
       su $ORACLE -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &
        sleep 5
      echo -n $"Starting Oracle: "
      su $ORACLE -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &
        ;;
*)
        echo "usage: $0 {start|stop|restart}"
        exit
        ;;
esac
exit


2. Update oratab file 


[root@oraclesrv ~]# cat /etc/oratab
#

# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.
# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
LEARN:/u01/app/oracle/db1:Y


3. Change the permission & enable as a service 


[root@oraclesrv ~]#chmod 750 /etc/init.d/dbora

[root@oraclesrv ~]#systemctl enable dbora

[root@oraclesrv ~]#chkconfig dbora on

[root@oraclesrv ~]#service dbora start


4. Create a auto startup trigger inside CDB


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

Trigger created.


SQL> select trigger_name,status from dba_triggers where trigger_name='AFTER_STARTUP';
TRIGGER_NAME                     STATUS     
-------------------------       --------
AFTER_STARTUP                   DISABLED

SQL> alter trigger AFTER_STARTUP enable;
Trigger altered.

SQL> select trigger_name,status from dba_triggers where trigger_name='AFTER_STARTUP';
TRIGGER_NAME                        STATUS
------------------------------      -------
AFTER_STARTUP                       ENABLED

SQL> show pdbs
    CON_ID CON_NAME                    OPEN MODE  RESTRICTED
---------- --------------------------- ---------- ----------
         2 PDB$SEED                       MOUNTED
         3 LEARNPDB                       MOUNTED
logout
[root@oraclesrv ~]# ps -ef | grep -i pmon
oracle   11844    1  0 17:01 ?     00:00:00 ora_pmon_LEARN

[root@oraclesrv ~]# ps -ef | grep -i tns
oracle  6331  1 0 17:00 ? 00:00:00 /u01/app/oracle/db1/bin/tnslsnr LISTENER -inherit


5. Reboot the server & verify if services started automatically 

[root@oraclesrv ~]# reboot


[oracle@oraclesrv ~]$ ps -ef | grep -i pmon

[oracle@oraclesrv ~]$ ps -ef | grep -i tns
oracle    5829     1  0 17:07 ?        00:00:00 /u01/app/oracle/db1/bin/tnslsnr LISTENER -inherit

[oracle@oraclesrv ~]$ ps -ef | grep -i pmon
oracle   11071    1  0 17:07 ?     00:00:00 ora_pmon_LEARN


SQL> show pdbs
    CON_ID CON_NAME                     OPEN MODE  RESTRICTED
---------- ---------------------------- ---------- ----------
         2 PDB$SEED                       MOUNTED
         3 LEARNPDB                       MOUNTED

SQL> select trigger_name,status from dba_triggers where trigger_name='AFTER_STARTUP';
TRIGGER_NAME                      STATUS
----------------------------      -------
AFTER_STARTUP                     ENABLED

SQL> show pdbs
    CON_ID CON_NAME                     OPEN MODE  RESTRICTED
---------- --------------------------- ---------- ----------
         2 PDB$SEED                       MOUNTED
         3 LEARNPDB                       MOUNTED

SQL> show pdbs
    CON_ID CON_NAME                     OPEN MODE  RESTRICTED
---------- --------------------------- ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 LEARNPDB                       MOUNTED

SQL> show pdbs
    CON_ID CON_NAME                     OPEN MODE  RESTRICTED
---------- --------------------------- ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 LEARNPDB                       READ WRITE NO



That's it !

1 comment: