30

According to the documentation, so long as I'm not connected to a database, I can either delete a database in the console using:

DROP DATABASE dbname;

Or I can drop it using the wrapper tool dropdb.

Both give me an error saying the database doesn't exist, yet when in the console and typing the command \l, I get a list of databases including the one I want to delete.

                                          List of databases
           Name            |   Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
---------------------------+-----------+----------+-------------+-------------+-----------------------
 Blog_development          | myusername | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 Blog_test                 | myusername | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

The database name is Blog_development (and the one below it). I was playing with rails and trying to learn from the online documentation. I wanted to start over and delete everything.

When trying to delete it however, it says it doesn't exist. I'm brand new to PostgreSQL so I'm a bit lost, nothing in the documentation about this error other than it popping up when it doesn't exist. Of course it exists, it's right there.

2
  • 2
    Please always show the full, exact text of any error messages, and show your PostgreSQL version. Dec 27, 2012 at 2:34
  • Check the port your DB is running on. The tools such as dropdb, createdb etc will connect by default to 5432. This caught me out when my DB was actually running on 5433.
    – user35738
    Mar 17, 2014 at 11:32

1 Answer 1

43

Your database was created using double quotes so its name is now case-sensitive. Therefore, you now need to always use double quotes when referring to it:

drop database "Blog_test";

More details about quoted identifiers (a database name is an identifier just like a column or table name) can be found in the manual:
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

1
  • 3
    my rule of thumb always use lower case :( I had this same problem. Oct 19, 2013 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.