Created
February 25, 2013 04:16
-
-
Save Amitesh/5027713 to your computer and use it in GitHub Desktop.
kill all connection to db and drop postgresql db
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
Query pg_stat_activity and get the pid values you want to kill and issue select pg_terminate_backend(pid int) to them. | |
PostgreSQL 9.1 and below: | |
SELECT pg_terminate_backend(pg_stat_activity.procpid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = 'mydb_prod_jan'; | |
PostgreSQL 9.2 and above: | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = 'mydb_prod_jan'; | |
============================================ | |
DROP DATABASE mydb_prod_jan; | |
CREATE DATABASE mydb_prod_jan | |
WITH OWNER = postgres | |
ENCODING = 'UTF8' | |
TABLESPACE = pg_default | |
LC_COLLATE = 'POSIX' | |
LC_CTYPE = 'POSIX' | |
CONNECTION LIMIT = -1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment