重命名后 postgres 数据库不存在

postgres database does not exist after rename

我不是 sql 的新手,但我是 postgresql 的新手,我在使用 psql 时遇到重命名数据库的问题。下面是正在发生的事情。

psql -d postgres

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

postgres=# \q

db_1 重命名为 db_2

时似乎一切顺利

现在尝试登录 db_2

psql -d db_2 -U postgres

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

同样,如果我尝试 db_1

psql -d db_1 -U postgres

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

所以我重新登录:

psql -d postgres

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

postgres=# \q

db_2db_1 的重命名同样完美。

现在我可以重新登录 db_1

psql -d db_1 -U postgres

db_1=#

所以我想弄清楚为什么在将 db_1 重命名为 db_2

之后数据库似乎 return does not exist

在此之后:

psql -d postgres

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

做:

postgres=# \l

获取数据库列表。