Give the app role a statement_timeout
One query missing an index can hold a connection for minutes while the pool drains behind it. A timeout on the role turns that into an error the app can deal with.
ALTER ROLE app SET statement_timeout = '5s';
ALTER ROLE reporting SET statement_timeout = '5min';Use separate roles for the app and for reports, each with the limit its work needs. A query that really does need longer can set its own timeout for that one statement.
postgresqloperations