Bruce
Bruce

Reputation: 1071

postgres database does not exist after rename

I am not new to sql but I am to postgresql and I am having an issue with renameing database when using psql. Below is exactly what is happening.

psql -d postgres

postgres=# ALTER DATABASE db_1 RENAME TO db_2;
ALTER DATABASE

postgres=# \q

All appears to go well when renaming db_1 to db_2

Now when trying to login to db_2

psql -d db_2 -U postgres

psql: error: could not connect to server: FATAL:  database "db_2" does not exist

Equally if I try db_1

psql -d db_1 -U postgres

psql: error: could not connect to server: FATAL:  database "db_1" does not exist

So I log back in:

psql -d postgres

postgres=# ALTER DATABASE db_2 RENAME TO db_1;
ALTER DATABASE

postgres=# \q

Again the rename works perfectly from db_2 to db_1.

Now I can log back in to db_1

psql -d db_1 -U postgres

db_1=#

So I am trying to figure out why the database seems to return does not exist after renaming db_1 to db_2

Upvotes: 1

Views: 1319

Answers (1)

Adrian Klaver
Adrian Klaver

Reputation: 19742

After this:

psql -d postgres

postgres=# ALTER DATABASE db_1 RENAME TO db_2;
ALTER DATABASE

Do:

postgres=# \l

to get list of databases.

Upvotes: 1

Related Questions