Skip to content

PostgreSQL

Common parts of every card are described in Monitor window.

Detected by systemd units postgresql*, or binaries postgres, postmaster, pg_ctlcluster
Read every 60 s while the Monitor window shows the tab
Active probe pg_isready, then psql with a fixed SQL script over the local socket (off by default)
Test config none (see below)
Manual commands errors of postgresql.conf and pg_hba.conf; who listens on an untrusted socket

Per cluster (server): version, Port, state, Owner, data directory (data:), Configuration and Configuration directory (-D), Log, Binary, Process, Socket (with owner, and whether this account may write to it), TCP listeners, and with the active probe Role (primary or replica), connections and replicas.

Passive sources, as the session’s user:

  • pg_lsclusters -h (Debian), under timeout; only lines in the cluster format leave the host (with the active probe only: it is a program of postgresql-common, not a file read);
  • main postgres processes from ps, with -D, -p, config_file and data_directory read from /proc/<pid>/cmdline (arguments split on NUL, never on spaces);
  • five keys of postgresql.conf / postgresql.auto.conf, filtered on the host: port, listen_addresses, data_directory, max_connections, unix_socket_directories;
  • the server sockets with their owners and the TCP listeners of the found ports (and 5432);
  • User= of the units; postgres -V and psql -V with the active probe only.

Runs: logs in to the local server as the role named like this SSH account (peer authentication; on the postgres account that is a superuser), without password files (PGPASSFILE points nowhere, PGPASSWORD is cleared). Per server socket owned by the expected server account (pg_lsclusters owner, User= of the unit, or the owner of a socket directory others cannot write), at most 4, unix socket only with requirepeer:

  1. pg_isready -h <socket dir> -p <port> -t 3;
  2. if it accepts connections, psql -w -X -d postgres with PGAPPNAME=kryodesk, PGCONNECT_TIMEOUT=3, statement_timeout 3 s and a fixed SQL script: version, pg_is_in_recovery(), connections (pg_stat_database), pg_stat_replication (address, state, lag), replay delay, pg_stat_wal_receiver (status, host, port), and only with the privilege the errors of pg_file_settings and pg_hba_file_rules.

Traces on the host: two connections per server and minute: with log_connections a connection received line each (application_name kryodesk); without a role or pg_hba.conf entry for this account a FATAL: role … does not exist / no pg_hba.conf entry / Peer authentication failed line in the server log, then no more tries until Retry (also after any other failed connection of psql); the SQL in the log with log_statement=all.

None: PostgreSQL has no offline configuration test this account can run (the server binary refuses root and needs the data directory). Errors of postgresql.conf and pg_hba.conf come from pg_file_settings and pg_hba_file_rules: in the active probe (with the privilege, by default superuser) or with the manual commands as postgres.

Label Command What it does
Errors in postgresql.conf (pg_file_settings) sudo -u postgres psql -X -d postgres -c '<query>' settings that a reload would reject; connects to the local server as postgres over its unix socket (a log line with log_connections)
Errors in pg_hba.conf (pg_hba_file_rules, PostgreSQL 10+) sudo -u postgres psql -X -d postgres -c '<query>' lines of pg_hba.conf that a reload would reject
Who listens on <socket> sudo lsof -- <socket> for a socket not owned by the expected server account (KryoDesk does not connect to it)

psql is the path found on the host (on RHEL with PGDG packages it is not in sudo’s secure_path).

Scroll or pinch to zoom · drag to move · double-click to zoom · Esc or click outside to close