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.

Steps to manage the PostgreSQL service with systemctl on Linux:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. Confirm that the running cluster unit returned to active.
    $ systemctl is-active postgresql@18-main.service
    active
  7. Confirm that PostgreSQL is accepting local connections.
    $ sudo -u postgres pg_isready
    /var/run/postgresql:5432 - accepting connections
  8. 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.

  9. Start PostgreSQL after the maintenance window is complete.
    $ sudo systemctl start postgresql
  10. 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.

  11. 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'.
  12. 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.