5

I'm running Debian Stretch and PostgreSQL 10 from apt.postgresql.org. When I do:

postgresql disable --now postgresql

the database server doesn't stop. It says:

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).

But that probably of not much importance.

systemctl disable --now postgresql@10-main does the job, but I'm curious about postgresql unit. Its start, stop, restart, reload tasks work fine.

Am I missing something? Is this a bug or limitation of systemd? Or of PostgreSQL package?

And now that I look into it, systemctl disable postgresql doesn't prevent PostgreSQL from starting on boot. I'd like not to be tied to a particular version. I thought stopping and disabling PostgreSQL would be simply a matter of doing systemctl disable --now postgresql. But it turns out I've got to:

systemctl list-units 'postgresql*' \
    | grep ^postgresql \
    | awk '{print $1}' \
    | xargs -r -I{} -d\\n systemctl disable --now {}

And even that doesn't always work for some mysterious reasons. I have a copy of data dir for testing purposes. Then in a script I restore database to initial state (stop, rm, cp, start). After which I'm trying to stop and disable pg as above. It gets disabled, but doesn't stop. I can see all it's processes running before the command, I can see:

database system is ready to accept connections

in the log (supposedly fully started). But it just wouldn't. So right now I do:

systemctl stop postgresql
systemctl list-units ... | xargs ... systemctl disable {}

From the man page:

--now When used with enable, the units will also be started. When used with disable or mask, the units will also be stopped. The start or stop operation is only carried out when the respective enable or disable operation has been successful.

x-yuri
  • 2,141
  • 2
  • 24
  • 29
  • 1
    `postgresql.service` is a weird service that’s kinda intended to act as “all PostgreSQL instances at once”, but only partially works. (Compare also `journalctl -u postgresql.service`, for example.) I think it’s best to ignore that unit and use `postgresql@*.service` instead, since those are the real services (10 being the version and “main” the cluster). That is: `systemctl disable --now 'postgresql@*.service'` – Lucas Werkmeister Jan 07 '19 at 13:05
  • I'm guessing that the first sentence `postgresql disable --now postgresql` is a "typo", due to the question being `systemctl disable --now postgresql doesn't stop the daemon`, letting you know instead of editing it myself just in case. – Leo Gallego Jan 13 '20 at 05:05

0 Answers0