postgres best practice - ghdrako/doc_snipets GitHub Wiki
Set a statement timeout
ALTER DATABASE mydatabase SET statement_timeout = '60s';
For good measure you may also want to set your idle_in_transaction timeout
as well, which will cancel long running transaction that are no longer performing work.
ALTER DATABASE mydatabase SET idle_in_transaction timeout = '60s';
Use pg_stat_statement
CREATE EXTENSION pg_stat_statements;