PostgreSQL

Terminate PostgreSQL clients from the db you’re about to drop

For PostgreSQL 9.1 and below

SELECT pg_terminate_backend(pg_stat_activity.procpid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
  AND procpid <> pg_backend_pid();

For PostgreSQL 9.2 and above

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
  AND pid <> pg_backend_pid();

Totally ripped from stackoverflow.com .

Kept here for my personal future reference .
If you stumble over this post please check the stackoverflow link above .