Skip to content

Instantly share code, notes, and snippets.

@marcomalva
marcomalva / postgres_queries_and_commands.sql
Last active September 22, 2021 19:36 — forked from rgreenjr/postgres_queries_and_commands.sql
[PostgreSQL Query Snippets] Useful PostgreSQL Queries and Commands #SQL
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'