Methods of Oracle setting dB, monitoring and EM startup

Time:2022-4-25

1、 Windows system

Oracle provides the function of starting with the startup of the operating system. There are different setting methods in windows and Linux.

In windows, you can modify “my computer — > Management — > Service — > oracleservice $oracle_sid”, or directly use the win + R key to open the running window and enter services MSC can open the service, find the corresponding Oracle service, and then modify the startup type in its properties to automatic. Generally, it will be automatically set to automatic after installation on Windows system.

2、 Linux system

For Linux / Unix operating system, if you want to set automatic restart, what should you do? For this, Oracle provides the dbstart command to start.

First, the first step needs to be modified/etc/oratabFile, change n to y

[[email protected] ~]# vim /etc/oratab
LHR11G:/u01/app/oracle/product/11.2.0.4/dbhome_ 1: Y # change n to y

file/etc/oratabBy root SH script is created, and this file will also be updated when the instance is created with DBCA command. When$ORACLE_SID:$ORACLE_HOME:<N|Y>When set to y, the instance is allowed to start automatically. When set to N, the instance is not allowed to start automatically. The configuration in this file only acts as a switch, which does not specifically execute startup and shutdown. The specific operation is determined by$ORACLE_HOME/bin/dbstartAnd dbshut script. These two scripts will be checked during execution/etc/oratabThe configuration in the file can be continued only when it is y.

Next, you need to configure the startup file. There are two ways:

Method 1: configure / etc / RC d/rc. Local file (recommended)

In configuration/etc/oratabFile, and then add the following script to / etc / rc d/rc. Local or / etc / RC Local file (/ etc / rc.local is the soft connection file of / etc / rc.d/rc.local):

cat >> /etc/rc.d/rc.local <<"EOF"
#Restart DB
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
su oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"

#Restart em
export ORACLE_UNQNAME=LHR11G
su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
EOF

This method needs to pay attention to the following problems:
1. If the EM is not created in the environment, you do not need to add Oracle_ Unqname and emctl

2. Starting from Oracle 12C, since Emde (enterprise manager database express) replaces the original emdc (enterprise manager database control), it is no longer necessary to set the EM related content separately, but only need to configure the DB, for example:

cat >> /etc/rc.d/rc.local <<"EOF"
#Restart DB
export ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/dbhome_1
su oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
EOF

3. In CentOS 7, / etc / RC d/rc. The permission of local is reduced, so you need to execute the following command to give it executable permission:


chmod +x /etc/rc.d/rc.local

Finally, you can restart the OS for testing.

Method 2: configure the service

1. Create startup script

Create scripts using root/etc/rc.d/init.d/oracle, the script is as follows. Please modify the relevant contents of lines 6-9:


#!/bin/bash 
# chkconfig: 2345 99 10 
# description: Startup Script for oracle Databases 
# /etc/rc.d/init.d/oracle

export ORACLE_BASE=/u01/app/oracle/
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_UNQNAME=LHR11G

echo " " >> /var/log/oraclelog
echo `date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelog

case "$1" in
start)
echo "-----startup oracle-----" >> /var/log/oraclelog
su oracle -c "$ORACLE_HOME/bin/dbstart"
su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch /var/lock/subsys/oracle
echo `date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelog
echo "-----startup oracle successful-----" >> /var/log/oraclelog
echo "OK" 
;;

stop)
echo "-----shutdown oracle-----" >> /var/log/oraclelog
su oracle -c "$ORACLE_HOME/bin/dbshut"
su oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f /var/lock/subsys/oracle
echo `date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelogg
echo "-----shutdown oracle successful-----" >> /var/log/oraclelog
echo "OK" 
;;

restart)
echo "-----shutdown oracle-----" >> /var/log/oraclelog
su oracle -c "$ORACLE_HOME/bin/dbshut"
su oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f /var/lock/subsys/oracle
echo `date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelog
echo "-----shutdown oracle successful-----" >> /var/log/oraclelog

echo "-----startup oracle-----" >> /var/log/oraclelog
su oracle -c "$ORACLE_HOME/bin/dbstart"
su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch /var/lock/subsys/oracle
echo `date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelog
echo "-----startup oracle successful-----" >> /var/log/oraclelog
echo "OK" 
;;

*)
echo "Usage: 'basename $0' start|stop|restart" 
exit 1
esac
exit 0

2. Set permissions for scripts


[[email protected] ~]# chmod 755 /etc/rc.d/init.d/oracle

3. Establishment of services


[[email protected] ~]# chkconfig --add oracle
[[email protected] ~]# chkconfig oracle on
[[email protected] ~]# chkconfig --list oracle
oracle          0:off   1:off   2:on    3:on    4:on    5:on    6:off

4. Check whether it is effective

First test whether the service is effective by using the root user:


[[email protected] ~]# service oracle stop
[[email protected] ~]# service oracle start
[[email protected] ~]# service oracle restart

Restart the OS to verify whether it takes effect.

3、 Oracle 18C version

Starting from Oracle 18C, for stand-alone environment, you can use RPM package to directly install Oracle Software. After installation, a script will be generated, similar to /etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSION, this script can be used to start and shut down Oracle Software, so you can also use this script to directly configure startup:


cat >> /etc/rc.d/rc.local <<"EOF"
/etc/init.d/oracledb_ORCLCDB-18c start
/etc/init.d/oracledb_lhrsdb-18c start
EOF

chmod +x /etc/rc.d/rc.local

Restart the OS and the test passes.

4、 Summary

For these two methods, several problems needing attention:

  1. If there are multiple instances, multiple instances will start automatically.
  2. Monitoring will also start automatically.
  3. If the database is less than 18C, the detailed log of restart is:$ORACLE_HOME/shutdown.logand$ORACLE_HOME/startup.log。 Starting from Oracle 18C, the log file of dbstart is$ORACLE_HOME/rdbms/log/startup.log
  4. The environment variables of Oracle users need not be configured.
  5. ORACLE_UNQNAMEThe function of emctl is to set the environment variable of EM. emctl is to start OEM. If not, it can not be set.
  6. ORACLE_HOMEThe function of is to set the environment variables for database listening.
  7. For Oracle 10.2.0.1, listening cannot be started automatically. The script needs to be modified$ORACLE_HOME/bin/dbstart, modifyORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracleFor“ORACLE_HOME_LISTNER=$1
  8. For ASM and Rac environments, you only need to register the database resources in CRS to realize startup.
  9. Starting with Oracle 18C, you can use scripts /etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSIONTo start the Oracle database.
  10. The above methods are tested in Oracle 10g, 11g, 12cr1 (12.1.0.2), 12cr2 (12.2.0.1), 18C (12.2.0.2) and 19C (12.2.0.3).

This is the end of this article about Oracle setting dB, monitoring and EM startup. For more information about Oracle setting dB, monitoring and EM startup, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!