【问题标题】:How to switch from database in postgres with psql?如何使用 psql 从 postgres 中的数据库切换?
【发布时间】:2022-01-15 05:53:02
【问题描述】:

我尝试使用 postgres (14.1) 数据库中的 powershell 进行切换

所以我这样做:

postgres-# \l

然后我看到了所有的数据库。但是例如我现在如何切换到测试数据库?

  Name    |  Owner   | Encoding |         Collate          |          Ctype           |   Access privileges
-----------+----------+----------+--------------------------+--------------------------+-----------------------
 postgres  | postgres | UTF8     | English_Netherlands.1252 | English_Netherlands.1252 |
 template0 | postgres | UTF8     | English_Netherlands.1252 | English_Netherlands.1252 | =c/postgres          +
           |          |          |                          |                          | postgres=CTc/postgres
 template1 | postgres | UTF8     | English_Netherlands.1252 | English_Netherlands.1252 | =c/postgres          +
           |          |          |                          |                          | postgres=CTc/postgres
 test      | postgres | UTF8     | English_Netherlands.1252 | English_Netherlands.1252 |
(4 rows)

我是这样尝试的:

postgres-# -d --test

但这不起作用。

【问题讨论】:

    标签: postgresql psql


    【解决方案1】:

    使用\connect(或仅使用\c

    Quote from the manual

    \c\connect
    建立到 PostgreSQL 服务器的新连接。要使用的连接参数可以使用位置语法(数据库名称、用户、主机和端口中的一个或多个)指定,也可以使用第 34.1.1 节中详述的 conninfo 连接字符串来指定。如果没有给出参数,则使用与以前相同的参数建立新的连接。

    -d参数只能在启动psql时使用:

    PS c:\> psql -d test
    

    【讨论】:

    • 啊,好吧。谢谢!!好吧
    猜你喜欢
    • 2011-04-26
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 2012-04-19
    • 2014-07-01
    • 2016-07-31
    • 2017-11-09
    相关资源
    最近更新 更多