Managing the PostgreSQL service with systemctl is the control point for reloading authentication changes, restarting after server-level settings, stopping the database for maintenance, and checking whether the server is actually running.
On systemd based Linux hosts, PostgreSQL may appear as one service unit or as an umbrella unit plus versioned cluster units. Debian and Ubuntu commonly show postgresql.service as the umbrella service and units such as postgresql@18-main.service for the running cluster.
Use the unit names from the local host before restarting anything. The sample output uses the Debian and Ubuntu cluster layout; replace postgresql@18-main.service with the running unit shown by systemctl list-units, or use postgresql when the distribution exposes only one service unit.
Related: How to configure pg_hba.conf in PostgreSQL
Related: How to upgrade PostgreSQL safely
Steps to manage the PostgreSQL service with systemctl on Linux:
- List the installed PostgreSQL service unit files.
$ systemctl list-unit-files --type=service 'postgresql*' UNIT FILE STATE PRESET postgresql.service enabled enabled postgresql@.service indirect enabled 2 unit files listed.
postgresql@.service is a template. Actual cluster units include the version and cluster name, such as postgresql@18-main.service.
- List the currently loaded PostgreSQL service units.
$ systemctl list-units --type=service 'postgresql*' UNIT LOAD ACTIVE SUB DESCRIPTION postgresql.service loaded active exited PostgreSQL RDBMS postgresql@18-main.service loaded active running PostgreSQL Cluster 18-main ##### snipped #####
On Debian and Ubuntu, active exited on postgresql.service means the umbrella service is active; the versioned cluster unit is the database process to inspect for runtime state.
- Check the status of the running cluster unit.
$ sudo systemctl status postgresql@18-main.service --no-pager ● postgresql@18-main.service - PostgreSQL Cluster 18-main Loaded: loaded (/usr/lib/systemd/system/postgresql@.service; enabled-runtime; preset: enabled) Active: active (running) since Sun 2026-06-07 05:06:36 UTC; 53s ago Process: 65 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 18-main start (code=exited, status=0/SUCCESS) Main PID: 83 (postgres) ##### snipped ##### Jun 07 05:06:33 postgresql-demo systemd[1]: Starting postgresql@18-main.service - PostgreSQL Cluster 18-main... Jun 07 05:06:36 postgresql-demo systemd[1]: Started postgresql@18-main.service - PostgreSQL Cluster 18-main.Use sudo systemctl status postgresql on systems where the discovered service list shows only postgresql.service.
- Reload PostgreSQL after changing settings that accept a reload, such as many authentication and logging changes.
$ sudo systemctl reload postgresql
Reloading asks the server to reread reloadable configuration files. Parameters marked as requiring server start still need a restart.
- Restart PostgreSQL when the changed setting requires a server restart.
$ sudo systemctl restart postgresql
A restart disconnects active sessions and can abort in-flight transactions.
- Confirm that the running cluster unit returned to active.
$ systemctl is-active postgresql@18-main.service active
- Confirm that PostgreSQL is accepting local connections.
$ sudo -u postgres pg_isready /var/run/postgresql:5432 - accepting connections
- Stop PostgreSQL when maintenance requires the database to be offline.
$ sudo systemctl stop postgresql
Stopping PostgreSQL makes local and remote database connections fail until the service is started again.
- Start PostgreSQL after the maintenance window is complete.
$ sudo systemctl start postgresql
- Disable PostgreSQL from starting at boot and stop it immediately when the database should stay offline after reboot.
$ sudo systemctl disable --now postgresql Synchronizing state of postgresql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install disable postgresql Removed '/etc/systemd/system/multi-user.target.wants/postgresql.service'.
Omit --now when the service should keep running until the next reboot.
- Enable PostgreSQL at boot and start it immediately.
$ sudo systemctl enable --now postgresql Synchronizing state of postgresql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install enable postgresql Created symlink '/etc/systemd/system/multi-user.target.wants/postgresql.service' → '/usr/lib/systemd/system/postgresql.service'.
- Check recent PostgreSQL service logs when a start, reload, or restart does not return the expected state.
$ sudo journalctl --unit=postgresql@18-main.service --no-pager ##### snipped ##### Jun 07 05:07:32 postgresql-demo systemd[1]: Stopping postgresql@18-main.service - PostgreSQL Cluster 18-main... Jun 07 05:07:32 postgresql-demo systemd[1]: postgresql@18-main.service: Deactivated successfully. Jun 07 05:07:32 postgresql-demo systemd[1]: Stopped postgresql@18-main.service - PostgreSQL Cluster 18-main. Jun 07 05:07:32 postgresql-demo systemd[1]: Starting postgresql@18-main.service - PostgreSQL Cluster 18-main... Jun 07 05:07:35 postgresql-demo systemd[1]: Started postgresql@18-main.service - PostgreSQL Cluster 18-main.
Use the unit that failed in the previous step. For an umbrella-only service, use --unit=postgresql.service.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.