How to find the ports of all running PostgreSQL instances (as a non-rot user)

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 the easiest way.

Go to Source
Author: EM0