Psql 命令
Here we list some of the most common
psqlcommands. For a complete list, check out the PostgreSQL psql docs.
以下列出了最常用的psql命令,完整命令列表请查阅PostgreSQL psql docs
-
-c <command>, --command=<command>Tells
psqlto 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 -ccommands 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壳命令
\lList available datab
列出可用数据库
\c, \connectConnect to a PostgreSQL database using the given parameters.
使用给定参数连接到PostgreSQL数据库
-
\dList available tables. If optional argument NAME is given, describe table, view, or index in more detail.
列出可用表。