If you are trying to drop a database and getting an error like the following in PostgreSQL:
ERROR: cannot drop the currently open database
Then, the easiest technique to solve the problem is to restart your PostgreSQL server. I am using PGSQL 9.6, here was my command:
systemctl stop postgresql-9.6.service systemctl start postgresql-9.6.service
If you are using PostgreSQL 13 or above, you have an option to drop the database with force now. You may drop the database using the following:
DROP DATABASE database_to_drop WITH (FORCE);
Replace ‘database_to_drop’ with the database you would like to drop.