I tried to use a Nagios script for monitoring the number of database connections on a Postgres database and I reached this problem: these are counted as currently open-connections and measured every 5 minutes.
SELECT sum(numbackends) FROM pg_stat_database;
Still, this seems to miss a huge number of short-lived connections, so the statistics are far from the reality.
I tried to run the script manually and I observed big changes even between two connections made few seconds away one from another.
How could I get this information in a reliable way? like max(connectios) happened during a time interval.