Monday, September 19, 2022

::: Enable Automate Startup/Shutdown of Oracle Database and Listener on Linux :::.

continue from
https://teguhth.blogspot.com/2021/11/install-database-oracle-19c-in-linux.html

1. check /etc/oratab

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.

[oracle@teguhth bin]$ 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.
#
#
#tgh:/u01/app/oracle/product/19.0.0/dbhome_1:N
tgh:/u01/app/oracle/product/19.0.0/dbhome_1:Y
[oracle@teguhth bin]$

 
2. Create a file called '/etc/init.d/dboracle' as the root user

[root@teguhth ~]# cat /etc/init.d/dboracle
#!/bin/bash
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes
ORA_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
ORA_OWNER=oracle

case "$1" in
  'start')
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
    su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
     touch /var/lock/subsys/dboracle
   ;;
   
  'stop')
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
    su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
 touch /var/lock/subsys/dboracle
 
   ;;
  'status')
   su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl status"
   su root -c "ps -ef | grep oracle"   
   ;;
   
  '')
  echo "/etc/init.d/dboracle {start|stop|status}"
  ;;
 
esac

# End of script dboracle
[root@teguhth ~]#

[root@
teguhth ~]#

3. or you can using
[root@teguhth ~]# cat /etc/init.d/dboracle
#!/bin/bash
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes
ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
ORACLE_OWNER=oracle

case "$1" in
  'start')
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start"
    su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbstart
     touch /var/lock/subsys/dboracle
   ;;
  'stop')
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop"
    su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbshut
 touch /var/lock/subsys/dboracle
   ;;
esac

# End of script dboracle
[root@
teguhth ~]#


4. setting the privileges to 750.

[root@teguhth ~]# chmod 750 /etc/init.d/dboracle

5. add service
[root@teguhth ~]# chkconfig --add /etc/init.d/dboracle


6. add simbolic link  

root@teguhth ~]# ln -s /etc/init.d/dboracle /etc/rc.d/rc0.d/K01dbora
root@teguhth ~]# ln -s /etc/init.d/dboracle /etc/rc.d/rc3.d/S99dbora
root@teguhth ~]# ln -s /etc/init.d/dboracle /etc/rc.d/rc5.d/S99dbora


7. Testing the script

7.1 stop oracle
[root@teguhth ~]#  /etc/init.d/dboracle stop

7.2 start oracle
[root@teguhth ~]#  /etc/init.d/dboracle start
 

7.3 status oracle
[root@teguhth ~]#  /etc/init.d/dboracle status

7.4 oracle not command
[root@teguhth ~]#  /etc/init.d/dboracl
 
 7.5 log

[root@teguhth ~]#  /etc/init.d/dboracle stop

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 19-SEP-2022 10:37:43

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=teguhth)(PORT=1521)))
The command completed successfully
Since ORACLE_HOME is not set, cannot auto-stop Oracle Net Listener
Usage: /u01/app/oracle/product/19.0.0/dbhome_1/bin/dbshut ORACLE_HOME
Processing Database instance "tgh": log file /u01/app/oracle/product/19.0.0/dbhome_1/rdbms/log/shutdown.log
[root@teguhth ~]#
[root@teguhth ~]#  /etc/init.d/dboracle start

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 19-SEP-2022 10:39:53

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/19.0.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/teguhth/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=teguhth)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=teguhth)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                19-SEP-2022 10:39:53
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/teguhth/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=teguhth)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
Since ORACLE_HOME is not set, cannot auto-start Oracle Net Listener.
Usage: /u01/app/oracle/product/19.0.0/dbhome_1/bin/dbstart ORACLE_HOME
Processing Database instance "tgh": log file /u01/app/oracle/product/19.0.0/dbhome_1/rdbms/log/startup.log
[root@teguhth ~]#
 
 
[root@teguhth ~]#  /etc/init.d/dboracle
/etc/init.d/dboracle {start|stop|status}

[root@teguhth ~]#  

[root@teguhth ~]#  /etc/init.d/dboracle status

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 19-SEP-2022 13:13:55

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=teguhth)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                19-SEP-2022 12:31:28
Uptime                    0 days 0 hr. 42 min. 27 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/teguhth/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=teguhth)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=teguhth)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/tgh/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "tgh" has 1 instance(s).
  Instance "tgh", status READY, has 1 handler(s) for this service...
Service "tghXDB" has 1 instance(s).
  Instance "tgh", status READY, has 1 handler(s) for this service...
The command completed successfully
avahi       845      1  0 12:31 ?        00:00:00 avahi-daemon: running [teguhth.local]
oracle     1545      1  0 12:31 ?        00:00:00 /u01/app/oracle/product/19.0.0/dbhome_1/bin/tnslsnr LISTENER -inherit
root       3083   1339  0 12:40 pts/1    00:00:00 vi /etc/init.d/dboracle
oracle     3566      1  0 12:46 ?        00:00:00 ora_pmon_tgh
oracle     3568      1  0 12:46 ?        00:00:00 ora_clmn_tgh
oracle     3570      1  0 12:46 ?        00:00:00 ora_psp0_tgh
oracle     3572      1  2 12:46 ?        00:00:41 ora_vktm_tgh
oracle     3576      1  0 12:46 ?        00:00:00 ora_gen0_tgh
oracle     3578      1  0 12:46 ?        00:00:00 ora_mman_tgh
oracle     3582      1  0 12:46 ?        00:00:00 ora_gen1_tgh
oracle     3585      1  0 12:46 ?        00:00:00 ora_diag_tgh
oracle     3587      1  0 12:46 ?        00:00:00 ora_ofsd_tgh
oracle     3590      1  0 12:46 ?        00:00:00 ora_dbrm_tgh
oracle     3592      1  0 12:46 ?        00:00:00 ora_vkrm_tgh
oracle     3594      1  0 12:46 ?        00:00:00 ora_svcb_tgh
oracle     3596      1  0 12:46 ?        00:00:00 ora_pman_tgh
oracle     3598      1  0 12:46 ?        00:00:01 ora_dia0_tgh
oracle     3600      1  0 12:46 ?        00:00:00 ora_dbw0_tgh
oracle     3602      1  0 12:46 ?        00:00:00 ora_lgwr_tgh
oracle     3604      1  0 12:46 ?        00:00:00 ora_ckpt_tgh
oracle     3606      1  0 12:46 ?        00:00:00 ora_smon_tgh
oracle     3608      1  0 12:46 ?        00:00:00 ora_smco_tgh
oracle     3610      1  0 12:46 ?        00:00:00 ora_reco_tgh
oracle     3612      1  0 12:46 ?        00:00:00 ora_w000_tgh
oracle     3614      1  0 12:46 ?        00:00:00 ora_lreg_tgh
oracle     3616      1  0 12:46 ?        00:00:00 ora_w001_tgh
oracle     3618      1  0 12:46 ?        00:00:00 ora_pxmn_tgh
oracle     3622      1  0 12:46 ?        00:00:05 ora_mmon_tgh
oracle     3624      1  0 12:46 ?        00:00:00 ora_mmnl_tgh
oracle     3627      1  0 12:46 ?        00:00:00 ora_d000_tgh
oracle     3629      1  0 12:46 ?        00:00:00 ora_s000_tgh
oracle     3631      1  0 12:46 ?        00:00:00 ora_tmon_tgh
oracle     3633      1  0 12:46 ?        00:00:01 ora_m000_tgh
oracle     3642      1  0 12:46 ?        00:00:00 ora_tt00_tgh
oracle     3644      1  0 12:46 ?        00:00:00 ora_tt01_tgh
oracle     3646      1  0 12:46 ?        00:00:00 ora_tt02_tgh
oracle     3649      1  0 12:46 ?        00:00:00 ora_w002_tgh
oracle     3652      1  0 12:46 ?        00:00:00 ora_aqpc_tgh
oracle     3655      1  0 12:46 ?        00:00:04 ora_cjq0_tgh
oracle     3659      1  0 12:46 ?        00:00:00 ora_p000_tgh
oracle     3661      1  0 12:46 ?        00:00:00 ora_p001_tgh
oracle     3664      1  0 12:46 ?        00:00:00 ora_w003_tgh
oracle     3810      1  0 12:46 ?        00:00:00 ora_w004_tgh
oracle     3823      1  0 12:47 ?        00:00:00 ora_qm02_tgh
oracle     3834      1  0 12:47 ?        00:00:00 ora_q002_tgh
oracle     3836      1  0 12:47 ?        00:00:00 ora_q003_tgh
oracle     3839      1  0 12:47 ?        00:00:00 ora_w005_tgh
oracle     3844      1  0 12:47 ?        00:00:02 ora_m001_tgh
oracle     3846      1  0 12:47 ?        00:00:01 ora_m002_tgh
oracle     4467      1  0 12:56 ?        00:00:01 ora_m004_tgh
oracle     4473      1  0 12:56 ?        00:00:00 ora_w006_tgh
oracle     4478      1  0 12:56 ?        00:00:00 ora_w007_tgh
oracle     4555      1  0 12:58 ?        00:00:01 oracletgh (LOCAL=NO)
oracle     5584      1  0 13:12 ?        00:00:00 ora_m003_tgh
root       5670   1339  0 13:13 pts/1    00:00:00 /bin/bash /etc/init.d/dboracle status
root       5695   5670  0 13:13 pts/1    00:00:00 su root -c ps -ef | grep oracle
root       5698   5695  0 13:13 pts/1    00:00:00 bash -c ps -ef | grep oracle
root       5700   5698  0 13:13 pts/1    00:00:00 grep oracle
[root@teguhth ~]#
 
 8. check process

[root@teguhth ~]# ps -ef | grep oracle
avahi       813      1  0 10:35 ?        00:00:00 avahi-daemon: running [teguhth.local]
oracle     2940      1  0 10:39 ?        00:00:00 /u01/app/oracle/product/19.0.0/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle     3057      1  0 10:39 ?        00:00:00 ora_pmon_tgh
oracle     3059      1  0 10:39 ?        00:00:00 ora_clmn_tgh
oracle     3061      1  0 10:39 ?        00:00:00 ora_psp0_tgh
oracle     3064      1  2 10:39 ?        00:00:06 ora_vktm_tgh
oracle     3068      1  0 10:39 ?        00:00:00 ora_gen0_tgh
oracle     3070      1  0 10:39 ?        00:00:00 ora_mman_tgh
oracle     3074      1  0 10:39 ?        00:00:00 ora_gen1_tgh
oracle     3077      1  0 10:39 ?        00:00:00 ora_diag_tgh
oracle     3079      1  0 10:39 ?        00:00:00 ora_ofsd_tgh
oracle     3082      1  0 10:39 ?        00:00:00 ora_dbrm_tgh
oracle     3084      1  0 10:39 ?        00:00:00 ora_vkrm_tgh
oracle     3086      1  0 10:39 ?        00:00:00 ora_svcb_tgh
oracle     3088      1  0 10:39 ?        00:00:00 ora_pman_tgh
oracle     3090      1  0 10:39 ?        00:00:00 ora_dia0_tgh
oracle     3092      1  0 10:39 ?        00:00:00 ora_dbw0_tgh
oracle     3094      1  0 10:39 ?        00:00:00 ora_lgwr_tgh
oracle     3096      1  0 10:39 ?        00:00:00 ora_ckpt_tgh
oracle     3098      1  0 10:39 ?        00:00:00 ora_smon_tgh
oracle     3100      1  0 10:39 ?        00:00:00 ora_smco_tgh
oracle     3102      1  0 10:39 ?        00:00:00 ora_w000_tgh
oracle     3104      1  0 10:39 ?        00:00:00 ora_reco_tgh
oracle     3106      1  0 10:39 ?        00:00:00 ora_w001_tgh
oracle     3108      1  0 10:39 ?        00:00:00 ora_lreg_tgh
oracle     3110      1  0 10:39 ?        00:00:00 ora_pxmn_tgh
oracle     3114      1  1 10:39 ?        00:00:04 ora_mmon_tgh
oracle     3116      1  0 10:39 ?        00:00:00 ora_mmnl_tgh
oracle     3118      1  0 10:39 ?        00:00:00 ora_d000_tgh
oracle     3120      1  0 10:39 ?        00:00:00 ora_s000_tgh
oracle     3122      1  0 10:39 ?        00:00:00 ora_tmon_tgh
oracle     3126      1  0 10:39 ?        00:00:00 ora_m000_tgh
oracle     3146      1  0 10:40 ?        00:00:00 ora_tt00_tgh
oracle     3148      1  0 10:40 ?        00:00:00 ora_tt01_tgh
oracle     3150      1  0 10:40 ?        00:00:00 ora_tt02_tgh
oracle     3153      1  0 10:40 ?        00:00:00 ora_w002_tgh
oracle     3155      1  0 10:40 ?        00:00:00 ora_aqpc_tgh
oracle     3158      1  0 10:40 ?        00:00:00 ora_cjq0_tgh
oracle     3163      1  0 10:40 ?        00:00:00 ora_p000_tgh
oracle     3170      1  0 10:40 ?        00:00:00 ora_p001_tgh
oracle     3232      1  0 10:40 ?        00:00:00 ora_w003_tgh
oracle     3381      1  0 10:40 ?        00:00:00 ora_w004_tgh
oracle     3397      1  0 10:40 ?        00:00:00 ora_qm02_tgh
oracle     3399      1  0 10:40 ?        00:00:00 ora_qm03_tgh
oracle     3401      1  0 10:40 ?        00:00:00 ora_q002_tgh
oracle     3404      1  0 10:40 ?        00:00:00 ora_q003_tgh
oracle     3406      1  0 10:40 ?        00:00:00 ora_q004_tgh
oracle     3411      1  0 10:40 ?        00:00:00 ora_m001_tgh
oracle     3413      1  0 10:40 ?        00:00:00 ora_m002_tgh
oracle     3461      1  0 10:40 ?        00:00:00 ora_q005_tgh
oracle     3463      1  0 10:40 ?        00:00:00 ora_q006_tgh
oracle     3465      1  0 10:40 ?        00:00:00 ora_q007_tgh
oracle     3467      1  0 10:40 ?        00:00:00 ora_q008_tgh
oracle     3469      1  0 10:40 ?        00:00:00 ora_q009_tgh
oracle     3471      1  0 10:40 ?        00:00:00 ora_q00a_tgh
oracle     3473      1  0 10:40 ?        00:00:00 ora_q00b_tgh
oracle     3475      1  0 10:40 ?        00:00:00 ora_q00c_tgh
oracle     3477      1  0 10:40 ?        00:00:00 ora_q00d_tgh
oracle     3479      1  0 10:40 ?        00:00:00 ora_q00e_tgh
oracle     3481      1  0 10:40 ?        00:00:00 ora_q00f_tgh
oracle     3483      1  0 10:40 ?        00:00:00 ora_q00g_tgh
oracle     3485      1  0 10:40 ?        00:00:00 ora_q00h_tgh
oracle     3487      1  0 10:40 ?        00:00:00 ora_q00i_tgh
oracle     3490      1  0 10:40 ?        00:00:00 ora_q00j_tgh
oracle     3492      1  0 10:40 ?        00:00:00 ora_q00k_tgh
oracle     3494      1  0 10:40 ?        00:00:00 ora_q00l_tgh
oracle     3496      1  0 10:40 ?        00:00:00 ora_q00m_tgh
oracle     3577      1  0 10:42 ?        00:00:00 ora_m003_tgh
root       3713   1402  0 10:44 pts/1    00:00:00 grep --color=auto oracle
[root@teguhth ~]#  ]

9. or using complete script

[root@teguhth ~]#
[root@teguhth ~]# cat /etc/init.d/dboracle
#!/bin/bash
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes
ORA_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
ORA_OWNER=oracle

case "$1" in
  'start')
    echo -n $"Starting Oracle DB:"
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" &
    touch /var/lock/subsys/dboracle
    exit
   ;;
   
  'stop')
    echo -n $"Shutting down Oracle DB:"
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"  &
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" &
    touch /var/lock/subsys/dboracle
     exit
   ;;
 
 'status')
   echo -n $"Status Oracle DB:"
   su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl status"
   su root -c "ps -ef | grep oracle"   
   exit
   ;;
   
   'restart')
    echo -n $"Restart Oracle DB:"
    echo -n $"Shutting down Oracle DB:"
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"

    sleep 5
   
    echo -n $"Starting Oracle DB:"
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
    touch /var/lock/subsys/dboracle
    exit    
  ;;     
 
   *)
      echo "usage: $0 {start|stop|restart|status}"      
      echo "/etc/init.d/dboracle {start|stop|restart|status}"
        exit
  ;;
 
esac

# End of script dboracle
[root@teguhth ~]#

No comments:

Post a Comment

Popular Posts