Last active
August 29, 2015 14:04
-
-
Save sponomarev/2c897cf81a6ac5571f4e to your computer and use it in GitHub Desktop.
PG query management in simple query snippets
This file contains 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
-- This queries were tested on PostgreSQL 9.3.4 | |
-- Provides detailed information about servers current connections | |
SELECT datname as database, | |
pid, | |
user as username, | |
application_name as application, | |
client_addr as client_address, | |
query | |
FROM pg_stat_activity; | |
-- Terminates all connections to specific database | |
SELECT pg_terminate_backend(pid) | |
FROM pg_stat_activity | |
WHERE datname = 'foo'; | |
-- Terminates all connections tied to specific user | |
SELECT pg_terminate_backend(pid) | |
FROM pg_stat_activity | |
WHERE user = 'user'; | |
-- Terminates all connections except your own process | |
SELECT pg_terminate_backend(pid) | |
FROM pg_stat_activity | |
WHERE pid <> pg_backend_pid(); | |
-- Terminates all connections except your own user | |
SELECT pg_terminate_backend(pid) | |
FROM pg_stat_activity | |
WHERE user <> current_user; | |
-- Cancels all connections to specific database | |
SELECT pg_cancel_backend(pid) | |
FROM pg_stat_activity | |
WHERE datname = 'foo'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment