Advertisement
Dyrcona

query_duration.sql

Jan 19th, 2022
958
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Got this from Jason Boyer to report query duration, client and the query string.
  3.  */
  4. SELECT pid as "PID", now()-query_start AS "Duration", state AS "State",
  5. client_addr AS "Client", application_name as "Application",
  6. REGEXP_REPLACE(REPLACE(SUBSTRING(TRIM(LEADING ' ' FROM query) FOR 140), E'\\n', ' '), E'\\s+', ' ', 'g') AS "Query"
  7. FROM pg_stat_activity
  8. WHERE state NOT LIKE 'idle%'
  9. AND query NOT LIKE '%now()-query_start%'
  10. AND query NOT LIKE 'START_REPLICATION%'
  11. ORDER BY query_start DESC;
  12.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement