Comment 5 for bug 1772601

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

I think I know what is happening here.

Under the systemd booted systems, pg_ctlcluster usually re-execs systemctl and starts/stops the appropriate postgresql@ instance unit.

The unit itself... executes pg_ctlcluster however with _SYSTEMCTL_SKIP_REDIRECT set, such that the actual code to spawn and manage postgresql cluster is used.

However, there is extra logic when to use systemctl, and when to bypass it.

Ideally, in this case, the charm should be resilient and it should ensure that systemctl redirection was not skipped, such that postgresql cluster is spawned a systemd unit; and not as a child.

E.g. note the
    # if extra options are given, proceed with pg_ctlcluster with a warning
    if (@postgres_auxoptions != 0 or @pg_ctl_opts_from_cli != 0 or $bindir) { # extra options given
        print "Notice: extra pg_ctl/postgres options given, bypassing systemctl for $action operation\n" if (-t 1);
    # if we are root, redirect to systemctl unless stopping a cluster running outside systemd

I would love to check the charm details, to see what exactly it invokes. Ideally it should figure out the default cluster, check if pid 1 is upstart; check if /run/systemd/system exists; and execute the most native command possible - e.g. systemctl start postgresql@9.5-main.service; not pg_ctlcluster 9.5 main start