Here is a patch that adds the following to pg_stat_database: - number of connections
Is it expected behaviour to not count idle connections? The connection is included after it is aborted but not while it was idle.
- number of sessions that were not disconnected regularly - total time spent in database sessions - total time spent executing queries - total idle in transaction time
This is useful to check if connection pooling is working. It also helps to estimate the size of the connection pool required to keep the database busy, which depends on the percentage of the transaction time that is spent idling.