Psql 命令
Here we list some of the most common
psql
commands. For a complete list, check out the PostgreSQL psql docs.
以下列出了最常用的psql
命令,完整命令列表请查阅PostgreSQL psql docs
-
-c <command>, --command=<command>
Tells
psql
to execute the string <command>
without entering the client shell. The<command>
string can be either a backslash command or a SQL command, but not a combination. Multiple -c
commands can be chained.
无需进入客户端壳层,告知psql
执行<command>
,<command>
string可以是反斜线命令也可以是SQL命令,但是不能两者组合。多个-c
可以链接。
-d <name>, --dbname=<name>
Denotes the
<name>
of the database to connect to.
指示要连接的数据库名称<name>
-h <hostname>, --host=<hostname>
Denotes the
<hostname>
of the machine where the PostgreSQL server is running.
指示PostgreSQL服务器运行的机器名称<hostname>
-U <username>, --username=<username>
Denotes the
<username>
of the user with which to connect to the database.
指示连接到数据库的用户名称<username>
Common psql commands include:
一般psql命令包括:
# Connect to the database 'tutorial' with username 'postgres'
# 用户名为'postgres'的用户连接到数据库'tutorial'
psql -U postgres -h localhost -d tutorial
# Backup your database to a .csv file
# 将数据库被分为.CSV文件
psql -d tutorial -c "\COPY tutorial TO tutorial.csv DELIMITER ',' CSV"
Psql壳命令
\l
List available datab
列出可用数据库
\c, \connect
Connect to a PostgreSQL database using the given parameters.
使用给定参数连接到PostgreSQL数据库
-
\d
List available tables. If optional argument NAME is given, describe table, view, or index in more detail.
列出可用表。