PostgreSQL: Drop Database but DB is still there

Did you type a ; after the DROP DATABASE test_db? Did PostgreSQL print a response to your command?


I had a similar issue when working on a Rails 6 application in Ubuntu 20.04 with PostgreSQL as my database.

When I run the command:

DROP DATABASE my-db;

The database is dropped successfully, however, the schema for the database is still left.

So when I run the command:

CREATE DATABASE my-db;

And I check the tables in the newly created database, I realized they still contained the same tables as the previously deleted database, even though I have not run any migration.

Here's how I fixed it:

Instead of running the command:

DROP DATABASE my-db;

run the command:

DROP DATABASE IF EXISTS my-db;

This deletes the database and it's corresponding schema.

That's all.

I hope this helps