`systemctl disable --now postgresql` 不会停止守护进程

x-y*_*uri 5 postgresql systemd systemctl

我正在运行来自 apt.postgresql.org 的 Debian Stretch 和 PostgreSQL 10。当我做:

postgresql disable --now postgresql
Run Code Online (Sandbox Code Playgroud)

数据库服务器不会停止。它说:

Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.                                                                                                
Executing: /lib/systemd/systemd-sysv-install disable postgresql                                      
insserv: warning: current start runlevel(s) (empty) of script `postgresql' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `postgresql' overrides LSB defaults (0 1 6).
Run Code Online (Sandbox Code Playgroud)

但这可能并不重要。

systemctl disable --now postgresql@10-main做这份工作,但我对postgresql单位很好奇。它的start, stop,任务restart工作reload正常。

我错过了什么吗?这是错误还是限制systemd?或者 PostgreSQL 包?

现在我调查了一下,并systemctl disable postgresql没有阻止 PostgreSQL 在启动时启动。我不想被特定的版本所束缚。我认为停止和禁用 PostgreSQL 只需要执行以下操作即可systemctl disable --now postgresql。但事实证明我必须:

systemctl list-units 'postgresql*' \
    | grep ^postgresql \
    | awk '{print $1}' \
    | xargs -r -I{} -d\\n systemctl disable --now {}
Run Code Online (Sandbox Code Playgroud)

但由于某些神秘的原因,这种方法并不总是有效。我有一份数据目录的副本用于测试目的。然后在脚本中我将数据库恢复到初始状态(stop、rm、cp、start)。之后我尝试如上所述停止并禁用 pg。它被禁用,但不会停止。我可以看到命令之前运行的所有进程,我可以看到:

database system is ready to accept connections
Run Code Online (Sandbox Code Playgroud)

在日志中(据说已完全启动)。但它就是不会。所以现在我这样做:

systemctl stop postgresql
systemctl list-units ... | xargs ... systemctl disable {}
Run Code Online (Sandbox Code Playgroud)

手册页

--now 与enable一起使用时,单元也将启动。当与禁用或掩码一起使用时,单元也将被停止。仅当相应的启用或禁用操作成功时,才会执行启动或停止操作。