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.

Steps to manage PostgreSQL service with systemctl in Linux:

  1. Identify the installed PostgreSQL service unit names.
    $ systemctl list-unit-files --type=service | grep --extended-regexp '^postgresql(@|\.)'
    postgresql.service                         enabled
    postgresql@.service                        enabled

    On Debian and Ubuntu, postgresql@.service is a template used for instance units such as postgresql@14-main.service.

  2. 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@14-main.service    loaded active running PostgreSQL Cluster 14-main
  3. Check the overall PostgreSQL service status.
    $ sudo systemctl status postgresql
    ● postgresql.service - PostgreSQL RDBMS
         Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; preset: enabled)
         Active: active (exited) since Sun 2025-12-14 11:40:19 UTC; 2min 11s ago
        Process: 3180 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
       Main PID: 3180 (code=exited, status=0/SUCCESS)
    ##### snipped #####

    On some Debian-based systems, postgresql.service is an umbrella unit and can show active (exited) even when cluster units are running.

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

  5. Restart the PostgreSQL service.
    $ sudo systemctl restart postgresql

    A restart interrupts active connections and can cause transient errors in applications during the restart window.

  6. Stop the PostgreSQL service.
    $ sudo systemctl stop postgresql

    Stopping the service makes the database unavailable until it is started again.

  7. Start the PostgreSQL service.
    $ sudo systemctl start postgresql
  8. Disable PostgreSQL from starting on boot.
    $ sudo systemctl disable --now postgresql
    Removed /etc/systemd/system/multi-user.target.wants/postgresql.service.

    The --now option stops the service immediately.

  9. Enable PostgreSQL to start on boot.
    $ sudo systemctl enable --now postgresql
    Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.

    The --now option starts the service immediately.

  10. View recent unit logs when the service shows failed or exits unexpectedly.
    $ sudo journalctl --unit=postgresql.service --no-pager --lines=50
    Dec 14 11:40:19 host systemd[1]: Starting PostgreSQL RDBMS...
    Dec 14 11:40:19 host systemd[1]: Started PostgreSQL RDBMS.
    ##### snipped #####
  11. Verify the database is accepting local connections.
    $ sudo -u postgres pg_isready
    /var/run/postgresql:5432 - accepting connections