Skip to main content

How to Start and Stop Oracle Database and Listener Automatically with Linux 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;
/





If you like please follow and comment

Comments

Popular posts from this blog

WebLogic migration to OCI using WDT tool

WebLogic migration to OCI using WDT tool Oracle WebLogic Deploy Tool (WDT) is an open-source project designed to simplify and streamline the management of Oracle WebLogic Server domains. With WDT, you can export configuration and application files from one WebLogic Server domain and import them into another, making it a highly effective tool for tasks like migrating on-premises WebLogic configurations to Oracle Cloud. This blog outlines a detailed step-by-step process for using WDT to migrate WebLogic resources and configurations. Supported WLS versions Why Use WDT for Migration? When moving Oracle WebLogic resources from an on-premises environment to Oracle Cloud (or another WebLogic Server), WDT provides an efficient and reliable approach to: Discover and export domain configurations and application binaries. Create reusable models and archives for deployment in a target domain. Key Pre-Requisites Source System: An Oracle WebLogic Server with pre-configured resources such as: Applica...

How to Validate TDE Wallet Password in Oracle Database

How to Validate TDE Wallet Password in Oracle Database Validating the Transparent Data Encryption (TDE) wallet password is crucial, especially when ensuring that the password is correct without using the OPEN or CLOSE commands in the database. This blog post explains a straightforward method to validate the TDE password using the mkstore utility. Steps to Validate TDE Wallet Password Follow these steps to validate the TDE wallet password: Step 1: Copy the Keystore/Wallet File Navigate to your existing TDE wallet directory. Copy only the ewallet.p12 file to a new directory. If a cwallet.sso file exists, do not copy it . The absence of cwallet.sso ensures that the wallet does not use auto-login, forcing the utility to prompt for the password. Step 2: Validate Using mkstore Use the mkstore utility to check the contents of the wallet file. The mkstore utility will prompt you for the TDE wallet password, allowing you to validate its correctness. Command Syntax To display the conten...

Rename a PDB in Oracle Database Multitenant Architecture in TDE and Non TDE Environment

Rename a PDB in Oracle Database Multitenant Architecture I am sharing a step-by-step guide to help you rename a PDB. This approach uses SQL commands. Without TDE or encryption Wallet Initial Check Check the Current Database Name and Open Mode: SQL > SELECT NAME, OPEN_MODE FROM V$DATABASE; NAME OPEN_MODE --------- -------------------- BEECDB READ WRITE List Current PDBs: SQL > SHOW PDBS; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 FUAT READ WRITE NO We need to RENAME FUAT to BEE  Steps to Rename the PDB Step 1: Export ORACLE_SID Set the Oracle SID to the Container Database (CDB): export ORACLE_SID=BEECDB Step 2: Verify Target PDB Name Availability If the target PDB name is different from the current PDB name, ensure no service exists with the target PDB name. Run SQL to Check Exi...