I have a monitoring script (running as an unprivileged user) that needs to check all instances of Postgres currently running on the same host (Ubuntu Linux 18.04). Is there an easy way to find all their port numbers?
I was thinking of listing all files matching /var/run/postgresql/.s.PGSQL.*
but I'm not sure whether this is reliable or the easiest way.
An easy way with Debian/Ubuntu would be to use
pg_lsclusters
(as provided by thepostgresql-common
package). This command lists the clusters with ports, statuses and other information:May be something like this: