在MySQL中,我使用use database_name;

psql的等价是什么?


当前回答

你可以使用

\ c dbname

如果你想查看POSTGRESQL或SQL的所有可能命令,请执行以下步骤:

rails dbconsole (您将被重定向到您当前的ENV数据库) ? (适用于POSTGRESQL命令)

or

\ h (适用于SQL命令) 按Q退出

其他回答

使用下面的语句切换到内部的不同数据库 您的postgreSQL RDMS

\c databaseName

虽然问题中没有明确说明,但目的是连接到特定的模式/数据库。

另一种选择是直接连接到模式。例子:

Sudo -u postgres PSQL -d my_database_name

来源:man psql:

-d dbname
--dbname=dbname
   Specifies the name of the database to connect to. This is equivalent to specifying dbname as the first non-option argument on the command line.

   If this parameter contains an = sign or starts with a valid URI prefix (postgresql:// or postgres://), it is treated as a conninfo string. See Section 31.1.1, “Connection Strings”, in the
   documentation for more information.

您还可以使用不同的ROLE连接到数据库,如下所示。

\connect DBNAME ROLENAME;

or

\c DBNAME ROLENAME;
  Connect to database:

  Method 1 : enter to db : sudo -u postgres psql

  Connect to db : \c dbname

  Method 2 : directly connect to db : sudo -u postgres psql -d my_database_name

在PSQL提示符下,你可以这样做:

\connect (or \c) dbname