Managing the PostgreSQL service is required when applying configuration changes, performing upgrades, or recovering from a failed startup. Service status and logs also confirm whether the database is available before troubleshooting applications and connection settings.
On modern Linux distributions, systemd controls PostgreSQL through one or more service units managed by systemctl. Some platforms use a single postgresql.service unit, while Debian-based systems often expose both an umbrella postgresql.service and instance units such as postgresql@<version>-main.service for individual clusters.
Restarting the service terminates active database connections, so changes should be applied during a maintenance window when possible. Reloading is preferred for changes that do not require a full restart, but the exact unit to reload or restart should be confirmed first to avoid leaving the database offline.
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:
- Identify the installed PostgreSQL service unit names.
$ systemctl list-unit-files --type=service | grep --extended-regexp '^postgresql(@|\.)' postgresql.service enabled enabled postgresql@.service indirect enabled
On Debian and Ubuntu, postgresql@.service is a template used for instance units such as postgresql@14-main.service.
- List active PostgreSQL units to determine what is currently running.
$ systemctl list-units --type=service 'postgresql*' UNIT LOAD ACTIVE SUB DESCRIPTION postgresql.service loaded active exited PostgreSQL RDBMS postgresql@16-main.service loaded active running PostgreSQL Cluster 16-main
- Check the overall PostgreSQL service status.
$ sudo systemctl status postgresql ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled) Active: active (exited) since Thu 2026-01-01 06:29:02 UTC; 44s ago Process: 3295 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 3295 (code=exited, status=0/SUCCESS) CPU: 2ms Jan 01 06:29:02 7234c64464d3 systemd[1]: Starting postgresql.service - PostgreSQL RDBMS... Jan 01 06:29:02 7234c64464d3 systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.On some Debian-based systems, postgresql.service is an umbrella unit and can show active (exited) even when cluster units are running.
- Reload the PostgreSQL service to apply configuration changes when supported.
$ sudo systemctl reload postgresql
If reload is not supported on the host, use a full restart instead.
- Restart the PostgreSQL service.
$ sudo systemctl restart postgresql
A restart interrupts active connections and can cause transient errors in applications during the restart window.
- Stop the PostgreSQL service.
$ sudo systemctl stop postgresql
Stopping the service makes the database unavailable until it is started again.
- Start the PostgreSQL service.
$ sudo systemctl start postgresql
- Disable PostgreSQL from starting on boot.
$ 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".
The --now option stops the service immediately.
- Enable PostgreSQL to start on boot.
$ 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.
The --now option starts the service immediately.
- View recent unit logs when the service shows failed or exits unexpectedly.
$ sudo journalctl --unit=postgresql.service --no-pager --lines=50 Jan 01 06:29:02 7234c64464d3 systemd[1]: Starting postgresql.service - PostgreSQL RDBMS... Jan 01 06:29:02 7234c64464d3 systemd[1]: Finished postgresql.service - PostgreSQL RDBMS. Jan 01 06:29:47 7234c64464d3 systemd[1]: Reloading postgresql.service - PostgreSQL RDBMS... Jan 01 06:29:47 7234c64464d3 systemd[1]: Reloaded postgresql.service - PostgreSQL RDBMS. Jan 01 06:29:47 7234c64464d3 systemd[1]: postgresql.service: Deactivated successfully. Jan 01 06:29:47 7234c64464d3 systemd[1]: Stopped postgresql.service - PostgreSQL RDBMS. Jan 01 06:29:47 7234c64464d3 systemd[1]: Stopping postgresql.service - PostgreSQL RDBMS... Jan 01 06:29:49 7234c64464d3 systemd[1]: Starting postgresql.service - PostgreSQL RDBMS... Jan 01 06:29:49 7234c64464d3 systemd[1]: Finished postgresql.service - PostgreSQL RDBMS. Jan 01 06:29:49 7234c64464d3 systemd[1]: postgresql.service: Deactivated successfully. Jan 01 06:29:49 7234c64464d3 systemd[1]: Stopped postgresql.service - PostgreSQL RDBMS. Jan 01 06:29:51 7234c64464d3 systemd[1]: Starting postgresql.service - PostgreSQL RDBMS... Jan 01 06:29:51 7234c64464d3 systemd[1]: Finished postgresql.service - PostgreSQL RDBMS. Jan 01 06:29:52 7234c64464d3 systemd[1]: postgresql.service: Deactivated successfully. Jan 01 06:29:52 7234c64464d3 systemd[1]: Stopped postgresql.service - PostgreSQL RDBMS. Jan 01 06:29:54 7234c64464d3 systemd[1]: Starting postgresql.service - PostgreSQL RDBMS... Jan 01 06:29:54 7234c64464d3 systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.
- Verify the database is accepting local connections.
$ sudo -u postgres pg_isready /var/run/postgresql:5432 - accepting connections
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.
