How To Manage and Troubleshoot PostgreSQL Service

1

Check the status of the PostgreSQL service.

systemctl status postgresql
2

Monitor the PostgreSQL log file in real-time.

tail -f /var/log/postgresql/postgresql-<VERSION>-main.log
3

View the PostgreSQL configuration file.

cat /etc/postgresql/<VERSION>/main/postgresql.conf
4

Display disk space usage.

df -h
5

Show real-time system processes and resource usage.

top
6

Stop the PostgreSQL service.

sudo systemctl stop postgresql.service
7

Start the PostgreSQL service.

sudo systemctl start postgresql.service
8

Check if the PostgreSQL service is active without producing output.

sudo systemctl is-active --quiet postgresql.service
9

Promote a standby PostgreSQL node to primary.

sudo -u postgres pg_ctl promote -D <STANDBY_NODE>