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 |
What the card shows
Section titled “What the card shows”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), undertimeout; 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
postgresprocesses fromps, with-D,-p,config_fileanddata_directoryread 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 -Vandpsql -Vwith the active probe only.
Active probe
Section titled “Active probe”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:
pg_isready -h <socket dir> -p <port> -t 3;- if it accepts connections,
psql -w -X -d postgreswithPGAPPNAME=kryodesk,PGCONNECT_TIMEOUT=3,statement_timeout3 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 ofpg_file_settingsandpg_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.
Test config
Section titled “Test config”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.
Manual commands
Section titled “Manual commands”| 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).