Skip to content

Instantly share code, notes, and snippets.

@nephest
Last active September 6, 2021 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nephest/b8c8d91c05fbad9b18df597896787727 to your computer and use it in GitHub Desktop.
Save nephest/b8c8d91c05fbad9b18df597896787727 to your computer and use it in GitHub Desktop.
--active query list
SELECT datname, pid, state, query, age(clock_timestamp(), query_start) AS age
FROM pg_stat_activity
WHERE state <> 'idle'
AND query NOT LIKE '% FROM pg_stat_activity %'
ORDER BY age;
--shutdown
SELECT pg_cancel_backend(<pid of the process>);
--kill
SELECT pg_terminate_backend(<pid of the process>);
--total relation size
SELECT pg_size_pretty(pg_total_relation_size('relation_name'));
--relation size
SELECT pg_size_pretty(pg_relation_size('relation_name'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment