Last active
January 18, 2018 15:59
-
-
Save sbaltus/36ec93a4631a6ae1208558a205d0cd67 to your computer and use it in GitHub Desktop.
Useful administration queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Lock management | |
| https://wiki.postgresql.org/wiki/Lock_Monitoring | |
| SELECT relname, | |
| mode, | |
| relation, | |
| database, | |
| pid, | |
| query | |
| FROM pg_locks | |
| INNER JOIN pg_stat_activity using(pid) | |
| INNER JOIN pg_class on pg_locks.relation = pg_class.oid; | |
| SELECT relation::regclass, * FROM pg_locks WHERE NOT GRANTED; | |
| -- Kill specific PID | |
| SELECT pg_terminate_backend(pid) | |
| FROM pg_stat_activity | |
| WHERE pid <> pg_backend_pid() | |
| AND datname = 'yourdbname' -- or any other condition, based on pg_stat_activity fields |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment