On Debian and Ubuntu, sudo systemctl enable postgresql is not what starts your database at boot. postgresql.service is a wrapper that runs /bin/true. The unit that runs your data is postgresql@version-cluster.service, and whether it starts at boot is decided by a text file:
pg_lsclusters # find your version and cluster name
cat /etc/postgresql/17/main/start.conf # auto | manual | disabled <-- the real switch
sudo systemctl status postgresql@17-main # the unit that actually runs postgres
After systemctl start postgresql you will not see "active (running)". You will see active (exited), because of what is in the unit file.
Table of Contents
What the package actually ships
These are the shipped units, taken from postgresql-common_293ubuntu1_all.deb unpacked on 10 August 2026 — not paraphrased. The header comment and the [Unit] and [Service] sections of postgresql.service:
# postgresql.service is the meta unit for managing all PostgreSQL clusters on
# the system at once. Conceptually, this unit is more like a systemd target,
# but we are using a service since targets cannot be reloaded.
#
# The unit actually managing PostgreSQL clusters is postgresql@.service,
# instantiated as postgresql@15-main.service for individual clusters.
[Unit]
Description=PostgreSQL RDBMS
[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on
ExecStart=/bin/true with RemainAfterExit=on is why the status is "active (exited)" and why it stays green whether or not a postmaster is alive. The real work is in the template unit, which invokes pg_ctlcluster:
[Unit]
Description=PostgreSQL Cluster %i
AssertPathExists=/etc/postgresql/%I/postgresql.conf
PartOf=postgresql.service
[Service]
Type=forking
ExecStart=-/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i start
ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
PIDFile=/run/postgresql/%i.pid
Why systemctl disable does not stop a cluster starting
The link between the two is a systemd generator, /usr/lib/systemd/system-generators/postgresql-generator, which runs on every boot and every daemon-reload. Its own comment: "This systemd generator creates dependency symlinks that make all PostgreSQL clusters with auto in their start.conf file be started/stopped/reloaded when postgresql.service is started/stopped/reloaded." The loop reads each /etc/postgresql/*/*/start.conf, skips anything that is not auto, and otherwise creates a Wants symlink under /run/systemd/generator/postgresql.service.wants/.
Two consequences that trip people up. Disabling the instance unit is pointless — the generator recreates the dependency from start.conf on the next boot regardless. And start.conf is the supported switch in the other direction as well. The shipped postgresql@.service has an [Install] section (WantedBy=multi-user.target) that the excerpt above leaves out, so enabling an instance by hand attaches it to multi-user.target without going through the generator; I did not test what that does to a cluster set to manual. To keep a cluster off at boot, edit the file:
echo manual | sudo tee /etc/postgresql/17/main/start.conf
sudo systemctl daemon-reload
The one thing systemctl enable postgresql does do is attach the meta unit to multi-user.target. On a stock install the package has already done that.
pg_ctl and postgres -C: checking config and status
These were run on PostgreSQL 17.10 (Homebrew, macOS 26.6 arm64) against scratch clusters. pg_ctl is the same program on Ubuntu. What the Ubuntu package ships and what pg_ctl reports can both be checked again with start-automatically-on-boot-ubuntu.sh: it unpacks postgresql-common from the Ubuntu archive, greps the units and the generator, then reruns the pg_ctl and postgres -C examples on a freshly initialised cluster and never goes near a database already on your machine.
$ pg_ctl configtest
pg_ctl: unrecognized operation mode "configtest" # exit 1
$ pg_ctl status
pg_ctl: no database directory specified and environment variable PGDATA unset
$ pg_ctl -D /tmp/scratch status
pg_ctl: no server running # exit 3
pg_ctl configtest does not exist; the operation modes are init, start, stop, restart, reload, status, promote, logrotate and kill. The real way to check a config file before restarting is postgres -C, which parses everything and reports the offending line:
$ postgres -D /tmp/scratch -C shared_buffers
16384 # exit 0
# after adding a bad line:
$ postgres -D /tmp/scratch -C shared_buffers
LOG: syntax error in file ".../postgresql.conf" line 848, near token "oops"
FATAL: configuration file ".../postgresql.conf" contains errors # exit 1
Exit code 3 from pg_ctl status is the useful one for scripts: 0 means running, 3 means not running. Note also that pg_ctl has nothing to do with booting. It starts a server now; it registers nothing. On Debian and Ubuntu, prefer pg_ctlcluster, which knows about the packaged layout, and let systemd call it.
The macOS contrast
There is no start.conf and no generator on macOS. Homebrew writes a launchd property list into ~/Library/LaunchAgents/, and the boot behaviour is one key in it. From a live MySQL agent, which is the same shape Homebrew writes for postgresql@17:
<key>RunAtLoad</key> <true/>
<key>KeepAlive</key> <true/>
<key>ProgramArguments</key>
<array><string>/opt/homebrew/opt/mysql@8.4/bin/mysqld_safe</string>...</array>
RunAtLoad is the equivalent of auto in start.conf; KeepAlive restarts it if it dies, which no PostgreSQL unit on Debian does deliberately (the template has Restart=on-failure commented out, because automatic restarts break pg_ctlcluster ... stop). Being a LaunchAgent rather than a LaunchDaemon, it starts at login, not at boot — brew services start gives you a database that is missing after a reboot until someone logs in.
What was not tested
No systemd command in this article was executed. The checks ran on macOS, with no Linux host and no container runtime, so systemctl, journalctl and pg_ctlcluster could not be run. The unit files, the generator and the start.conf logic are quoted from the Ubuntu package itself rather than tested, and the version number in your unit name will be whatever pg_lsclusters prints, not necessarily 17.