In this article, we will see how to drop a PostgreSQL database if there are active connections to it?
Below query is used to drop active connections on a database
Syntax for PostgreSQL 9.2 and later:
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'TARGET_DB' -- ← change this to your DB AND pid <> pg_backend_pid();
Syntax for PostgreSQL 9.1 and below 9.1:
Continue reading How to drop a PostgreSQL database if there are active connections to it