Once enabled, it automatically records all queries run against your database and records often and how long they took.
Enable: create extension pg_stat_statements
Note: it has a performance cost to leaving this always on, but it’s pretty small.
SELECT
(total_time / 1000 / 60) as total_minutes,
(total_time/calls) as average_time,