Skip to content

Instantly share code, notes, and snippets.

View marceloh's full-sized avatar

Marcelo marceloh

View GitHub Profile
@marceloh
marceloh / PostgreSQL handy commands
Created May 20, 2020 12:57 — forked from denitram/PostgreSQL handy commands
Potsgresql: handy commands
-- Viewing current PostgreSQL queries
-- source: http://chrismiles.info/systemsadmin/databases/articles/viewing-current-postgresql-queries/
SELECT datname,pid,query,query_start FROM pg_stat_activity ORDER BY query_start ASC;
-- top-like view of current queries, grouped by how many of the same query are running at that instant and the usernames belonging to each connection.
SELECT count(*) as cnt, usename, current_query FROM pg_stat_activity GROUP BY usename,current_query ORDER BY cnt DESC;
-- List databases creation dates
SELECT (pg_stat_file('base/'||oid ||'/PG_VERSION')).modification, datname FROM pg_database ORDER BY modification;
SELECT (pg_stat_file('base/'||oid ||'/PG_VERSION')).modification, datname FROM pg_database ORDER BY datname;