Unable to delete a database from postgres

Unable to delete a database from postgres

Description of issue

ERROR: database <db-name> is being accessed by other users

DETAIL: There is 1 other session using the database.
You have to terminate the connections to the database first, for that you can use the command.

  1. SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname='TARGET_DB';

Then run the command to delete database -
  1. drop databases <db-name>