自动停止数据库(dbshut)在 OL 7 的 systemd 中不能运行 (文档 ID 2364833.1)
适用于:
Oracle Database - Enterprise Edition - 版本 12.1.0.2 和更高版本本文档所含信息适用于所有平台
Linux x86-64
症状
在:12.1.0.2 版本,RDBMS
当在服务器关闭期间尝试停止 DB 时,自动关闭脚本得到以下错误:
Processing Database instance "XXXX1": log file /u01/app/oracle/product/12.1.0.2/dbhome_1/shutdown.log
Info: Database instance "XXXX" already down (PMON process not there).
这表明 PMON 在脚本被调用之前就被强制关闭。
当前使用的脚本配置是:
cat dbora.service
[Unit]
Description=The Oracle Database Service
After=network.target
[Service]
Type=forking
# Type=oneshot
RemainAfterExit=yes
KillMode=none
# Set this to something larger if it has an impact
TimeoutStopSec=0
ExecStart=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin/dbora start
ExecStop=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin/dbora stop
[Install]
# Puts wants directive for the other units in the relationship
WantedBy=default.target
systemctl enable dbora.service
systemctl daemon-reload
systemctl start dbora.service
以上脚本是从以下 Note 得到的:
How to Automate Startup/Shutdown of Oracle Database on Linux (Doc ID 222813.1)
原因
dbora 脚本内使用su oracle来执行命令,但是systemd无法监控这样的命令,因此无法跟踪该进程。
以下用到su - oracle的dbora 脚本:
ORA_HOME=/u01/app/oracle/product/12.1.0.2/dbhome_1
ORA_OWNER=oracle
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
# Remove "&" if you don't want startup as a background process.
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
touch /var/lock/subsys/dbora
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
rm -f /var/lock/subsys/dbora
;;
esac
因为这种情况,系统失去对服务的控制,从而不能及时停掉服务。
解决方案
更好的选择是指定用户和所有者详细信息后直接使用 dbstart 和 dbstop 脚本
Description=The Oracle Database Service
After=network.target
[Service]
Type=forking
RemainAfterExit=yes
KillMode=none
TimeoutStopSec=5min
User=oracle << 在这里替换成 oracle 软件具体用户 Group=oinstall
Group=oinstall
ExecStart=$ORACLE_HOME/bin/dbstart $ORACLE_HOME & ===> 请使用绝对路径代替 ORACLE_HOME
ExecStop=$ORACLE_HOME/bin/dbshut $ORACLE_HOME ===> 请使用绝对路径代替 ORACLE_HOME
Restart=no
[Install]
# Puts wants directive for the other units in the relationship
WantedBy=default.target
然后 systemd 就能控制这些服务
# systemctl status dbora.service
● dbora.service - The Oracle Database Service
Loaded: loaded (/usr/lib/systemd/system/dbora.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-02-01 12:19:53 GMT; 22s ago
Process: 3905 ExecStop=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin/dbshut /u01/app/oracle/product/12.1.0.2/dbhome_1 (code=exited, status=0/SUCCESS)
Process: 4043 ExecStart=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin/dbstart /u01/app/oracle/product/12.1.0.2/dbhome_1 & (code=exited, status=0/SUCCESS)
CGroup: /system.slice/dbora.service
├─4051 /u01/app/oracle/product/12.1.0.2/dbhome_1/bin/tnslsnr LISTENER -inherit
├─4143 ora_pmon_XXXXX
<snip>
└─4477 ora_q003_XXXX