The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/18/server-start.html
Description:
**PostgreSQL Version:** 18.1 (devel/snapshot) and 17.5
**Operating System:** Debian 12.11 (amd64)
**Installation Method:** Source compilation
**Configure Options:** `./configure --prefix=/usr/local/services/pgsql-18.1
--with-llvm --with-systemd`
**Description:**
I am encountering an issue starting the PostgreSQL service using systemd
after compiling from source with `--with-systemd`.
While the server starts correctly when invoking `pg_ctl` manually from the
command line, it fails to start when using a systemd unit file configured
with `Type=notify`, which references the documentation at
[https://www.postgresql.org/docs/current/server-start.html](https://www.postgresql.org/docs/current/server-start.html).
**Steps to Reproduce:**
1. Compile and install PostgreSQL with systemd support.
2. Create a systemd unit file as follows (using `pg_ctl` in ExecStart):
```Ini
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
User=postgres
WorkingDirectory=/usr/local/services/pgsql-18.1
# Using pg_ctl to start the service
ExecStart=/usr/local/services/pgsql-18.1/bin/pg_ctl start -D
/usr/local/services/pgsql-18.1/data -l /usr/local/services/pgsql-18.1/pg.log
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target
```
3. Run `sudo systemctl daemon-reload` and `sudo systemctl start postgresql`.
**Observed Result:**
The service hangs in the "activating" state until it times out, even though
the database process is actually running in the background. Systemd
eventually kills the process because it never receives the readiness
notification.
`pg.log` (even at debug5 level) shows no errors, confirming the database
started but the notification was not acknowledged by systemd.
**Analysis & Fix:**
Since `ExecStart` executes `pg_ctl`, but the `sd_notify` signal is sent by
the forked `postgres` process, systemd ignores the signal by default.
I found that adding the following lines to the `[Service]` section fixes the
issue entirely:
```Ini
NotifyAccess=all
PIDFile=/usr/local/services/pgsql-18.1/data/postmaster.pid
```
**Suggestion:**
The documentation regarding Systemd integration (specifically when using
`pg_ctl` combined with `Type=notify`) might be incomplete. It appears that
`NotifyAccess=all` is mandatory when `ExecStart` is a wrapper (like
`pg_ctl`) rather than the `postgres` binary itself.
I confirmed this behavior on both PostgreSQL v18.1 and v17.5 on Debian 12.
I suggest updating the documentation examples or adding a note about
`NotifyAccess` for users compiling with `--with-systemd`.
Best regards.