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 – > services – > oracleservice $oracle_sid", or directly use Win+R 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, in the first step, you need to modify the / etc/oratab file to change N to Y
[root@oracle ~]# vim /etc/oratab LHR11G:/u01/app/oracle/product/11.2.0.4/dbhome_1:Y #Change N to Y
The file / etc/oratab is created by root SH script is created, and this file will also be updated when the instance is created with dbca command. When $Oracle_ SID:$ORACLE_ When y: > is set to Y: < home, it is not allowed to start the instance 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/dbstart and dbshut scripts. The two scripts will check the configuration in the / etc/oratab file when executing, and can continue to execute 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)
After configuring the / etc/oratab file, 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
Use root to create the script / etc / RC d/init. D / oracle. The script is as follows. Please modify the relevant contents in 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
[root@oracle ~]# chmod 755 /etc/rc.d/init.d/oracle
3. Establishment of services
[root@oracle ~]# chkconfig --add oracle [root@oracle ~]# chkconfig oracle on [root@oracle ~]# 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, use the root user to test whether the service is effective:
[root@oracle ~]# service oracle stop [root@oracle ~]# service oracle start [root@oracle ~]# 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 it can also be used 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:
- If there are multiple instances, multiple instances will start automatically.
- Monitoring will also start automatically.
- If the database is less than 18c, the detailed log of restart is: $ORACLE_HOME/shutdown.log and $ORACLE_HOME/startup.log. Starting from Oracle 18c, the log file of dbstart is in $ORACLE_HOME/rdbms/log/startup.log
- The environment variables of oracle users need not be configured.
- ORACLE_UNQNAME is used to set the environment variable of EM, and emctl is used to start OEM. If not, you can not set it.
- ORACLE_HOME is used to set the environment variables for database listening.
- For Oracle 10.2.0.1, listening cannot be started automatically. Script $Oracle needs to be modified_ Home / bin / dbstart, modify ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle is "ORACLE_HOME_LISTNER=""
- For ASM and RAC environments, you only need to register the database resources in CRS to realize startup.
- Starting with Oracle 18c, you can use the script / etc / init d/oracledb_$ ORACLE_ SID-$ORACLE_ Version to start the Oracle database.
- 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).
About Me
● the author of this article: wheat seedling. Some contents are sorted out from the network. If there is infringement, please contact wheat seedling to delete
This article is originally published in the personal WeChat official account. DB treasure )Up
● QQ group number: 230161599, 618766405, wechat group private chat
● personal QQ number (646634621), micro signal (db_bao), indicating the reason for adding
● all rights reserved. Welcome to share this article. Please keep the source for reprint