If the server is powered off and restarted or restarted within the plan, the database instance and monitoring need to be started manually after the server's operating system is started. This paper introduces how to configure the start and shutdown of Oracle database as a system service, and automatically start / shut down the Oracle instance and monitoring when the operating system is started / shut down.
Assume that the value of the Oracle home environment variable is / oracle/home.
1. Start the shell script of the database instance
The script to start the Oracle database is / oracle/home/bin/dbstart, as follows:
sqlplus / as sysdba <<EOF startup; EOF
2. Restart the shell script of the database instance
The script to start the Oracle database is / oracle/home/bin/dbrestart, as follows:
sqlplus / as sysdba <<EOF shutdown immediate; startup; EOF
3. Close the shell script of the database instance
The script to start the Oracle database is / oracle/home/bin/dbshut, as follows:
sqlplus / as sysdba <<EOF shutdown immediate; EOF
4. System service profile script of oracle instance
If the system service is named Oracle, create the service configuration file / usr/lib/systemd/system/oracle.service, as follows:
[Unit] Description=Oracle RDBMS After=network.target [Service] Type=simple ExecStart=/usr/bin/su - oracle -c "/oracle/home/bin/dbstart >> /tmp/oracle.log" ExecReload=/usr/bin/su - oracle -c "/oracle/home/bin/dbrestart >> /tmp/oracle.log" ExecStop=/usr/bin/su - oracle -c "/oracle/home/bin/dbshut \>\> /tmp/oracle.log" RemainAfterExit=yes [Install] WantedBy=multi-user.target
5. System service profile script monitored by lsnrctl
If the system service is named lsnrctl, create the service configuration file / usr/lib/systemd/system/lsnrctl.service, as follows:
[Unit] Description=Oracle lsnrctl After=network.target [Service] Type=simple ExecStart=/usr/bin/su - oracle -c "/oracle/home/bin/lsnrctl start >> /tmp/lsnrctl.log" ExecReload=/usr/bin/su - oracle -c "/oracle/home/bin/lsnrctl reload >> /tmp/lsnrctl.log" ExecStop=/usr/bin/su - oracle -c "/oracle/home/bin/lsnrctl stop >> /tmp/lsnrctl.log" RemainAfterExit=yes [Install] WantedBy=multi-user.target
6. Reload service profile
systemctl daemon-reload
7. Start / stop / restart oracle and lsnrctl services
systemctl start oracle # Start the oracle service. systemctl restart oracle # Restart the oracle service. systemctl stop oracle # Close oracle service. systemctl start lsnrctl # Start the lsnrctl service. systemctl restart lsnrctl # Restart the lsnrctl service.. systemctl stop lsnrctl # Turn off the lsnrctl service.
8. Set oracle and lsnrctl services to start / stop
systemctl enable oracle # Set the Oracle instance service to power on and start automatically. systemctl enable lsnrctl # Set the Oracle monitoring service to power on and start automatically.
9. View the Oracle instance and listen to the start / stop logs.
The log of Oracle instance startup is in the / tmp/oracle.log file.
The start date of listening is in the / tmp/lsnrctl.log file.
Note that only when you start / close the Oracle instance and listen through systemctl, the log will be written. If you execute the script manually, the log will not be written.
10. Copyright notice
C language technology net original article, reprint please explain the article source, the author and the original link.
Source: C language technology network (www.freecplus.net)
Author: Manon Youdao
If this article is helpful to you, please like support or forward my article in your blog, thank you!!!
If there is a mistake in the article, or there is a mistake in the content, or other suggestions and opinions, please leave a message for correction, thank you very much!!!