Terminating all active connection and dropping database — PostgreSQL
While using PostgreSQL some time you may come across a case to drop whole database. If that database is actively being used you may get an error that cannot drop database due to active connections. Following 2 steps specified below database can be dropped.
Drop all active connections
Connect to server using admin login and switch to default DB postgre. Run this script to drop all active connections
SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'DatabaseName';
DROP DATABASE "DatabaseName";
For more such interesting technology related blogs, resources visit my site https://sharetechlinks.com/