如何在不离开当前psql会话的情况下进入数据库?

时间:2017-11-08 02:58:15

标签: postgresql

$ sudo -u postgres psql
postgres=# \list
                                   List of databases
     Name     |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
--------------+----------+----------+-------------+-------------+-----------------------
 linuxhowtodb | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres     | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |          |          |             |             | postgres=CTc/postgres
 template1    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |          |          | 

如何在不离开当前psql会话的情况下输入数据库linuxhowtodb?感谢。

请注意,如果我可以离开当前的psql会话,那么我可以运行以下命令来访问特定的数据库:

$ psql linuxhowtodb
psql (9.6.5)
Type "help" for help.

linuxhowtodb=> 

1 个答案:

答案 0 :(得分:3)

使用\ c:

postgres=# \c linuxhowtodb

From the documentation:

  

\ c或\ connect [-reuse-previous = on | off] [dbname [username] [host] [port] | conninfo]

     

建立与PostgreSQL服务器的新连接。要使用的连接参数可以使用位置语法或使用conninfo连接字符串来指定。

相关问题