0

我想在 psql 中连接到我新创建的名为“test”的数据库,我看到过这样的命令:

Connection
  \c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
                         connect to new database (currently "postgres")

这意味着什么?

我试着写:

  \c {test|- postgres|- localhost|- 5432|- | conninfo}

但出现错误:

invalid integer value "5432|-" for connection option "port"

我应该怎么办?

4

3 回答 3

2

你试过了吗

\c postgresql://user@localhost/test

或者

\c "host=localhost port=5432 dbname=test connect_timeout=10"

资源

于 2020-04-23T00:13:01.347 回答
2

\c 在您已经连接到数据库并想要连接到另一个数据库时使用。

例如,如果您与 postgres db 连接并想与 test 数据库连接,那么您可以做的是 \c test

如果使用 psql 然后

./psql -U postgres -d test -p 5432
于 2020-04-23T11:09:03.713 回答
0

我只是发现这种方式对像我这样的所有其他人都有效:

\l

这样您将看到您创建的数据库列表,如果您想查看某个表,那么

\c db_name

然后,如果数据库存在,您将成功连接它。

于 2020-04-23T04:57:12.770 回答