postgresqlpostmortem-debugging

Is there a way to get pg_stat_activity information without using an SQL connection?


pg_stat_activity holds extremely useful information for post-mortem analysis of various issues, especially concurrency-related, and so augmenting errors or logging with this data (properly filtered and correlated) is invaluable. However querying it requires getting a database connection which might be in short supply at the very moment it's most needed.

Is there a side-channel of some sort which would allow getting that information without the additional database connection?


Solution

  • Not really, but the parameter superuser_reserved_connections will help you. It defines the number of connections that are reserved for superusers precisely so that they can still connect, even if the connection limit is exhausted.

    Set the value high enough and have your monitoring process connect as superuser.