DBeaver / PostgreSQL: "Error: database already exists", but I can't find it
Asked Answered
W

4

20

I want to create database called "President" by rightclicking on PostgreSQL and selecting Create Database.

However, I get the error in the screenprint below.

I can create databases with other names like SomeOtherDatabase and SomeOtherDatabase2 (see screenprints).

Any ideas how I can find and delete the database "President" that seems to exist already?

enter image description here enter image description here

UPDATE!!

If I execute

select * from pg_database 

I get the following result:

enter image description here

So database "President" does seem to exist. (Meanwhile I deleted someOtherDatabase and someOtherDatabase2.)

However, if I execute

drop database President

I get:

enter image description here

Wildon answered 23/5, 2020 at 23:14 Comment(0)
S
5

You can query catalog view pg_database to check if the database already exists:

select datname from pg_database WHERE datname = 'president'

And drop it with drop database:

drop database president;

Note that Postgres' drop database syntax supports the if exists clause, which may come handy in your use case:

drop database if exists president;
Snobbery answered 23/5, 2020 at 23:17 Comment(3)
Thanks. The database does seem to exist because "select datname from pg_database WHERE datname = 'President'" returns "President". But "drop database President" returns "SQL Error [3D000]: ERROR: database "president" does not exist"..Wildon
@Frank: you created your database with double quotes, so the name is case sensitive now. You need to use drop database "President". And you should avoid double quoted identifiers in the futureLeigha
@– a_horse_with_no_name, It worked!! Thanks a lot :-) I was completely puzzled and this is definitely useful to know.Wildon
O
51

You can right click on the postgres database and select edit connection option. Under the PostgreSQL tab, check the Show all databases option.

Olnee answered 19/7, 2021 at 11:43 Comment(3)
Why wouldn't this be the default?Georgiageorgian
Jesus christ! spent 2 hours trying to figure out. Thanks!Intersperse
So much thank you on this! Spent at least an hour trying to figure this out!Gershom
F
23

2023 Update

  1. Right-click on your connection
  2. Click "Edit connection"
  3. Left panel, click "Connection settings"
  4. Select PostgreSQL tab Check the box "Show all databases"

enter image description here

enter image description here

Folse answered 25/11, 2022 at 15:27 Comment(1)
This option is not available on my mac M1Gastight
S
5

You can query catalog view pg_database to check if the database already exists:

select datname from pg_database WHERE datname = 'president'

And drop it with drop database:

drop database president;

Note that Postgres' drop database syntax supports the if exists clause, which may come handy in your use case:

drop database if exists president;
Snobbery answered 23/5, 2020 at 23:17 Comment(3)
Thanks. The database does seem to exist because "select datname from pg_database WHERE datname = 'President'" returns "President". But "drop database President" returns "SQL Error [3D000]: ERROR: database "president" does not exist"..Wildon
@Frank: you created your database with double quotes, so the name is case sensitive now. You need to use drop database "President". And you should avoid double quoted identifiers in the futureLeigha
@– a_horse_with_no_name, It worked!! Thanks a lot :-) I was completely puzzled and this is definitely useful to know.Wildon
F
3

2024 Update

The option to show all databases is next to the Database input on my MacBook: Screenshot of the postgres connection configuration with a red arrow to the checkbox to show all databases

Checking this should also show all available databases.

Flump answered 12/4, 2024 at 16:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.