psql 常用命令

 

一,命令行选项

Usage:
  psql [OPTION]... [DBNAME [USERNAME]]

 -?, --help[=options]     show this help, then exit

  -d, --dbname=DBNAME      database name to connect to (default: "postgres")

  -h, --host=HOSTNAME      database server host or socket directory (default: "local socket")
  -p, --port=PORT          database server port (default: "5432")
  -U, --username=USERNAME  database user name (default: "postgres")

二,psql内部命令

general

  \copyright             show PostgreSQL usage and distribution terms

  \q                     quit psql

help

  \? [commands]          show help on backslash commands
  \? options             show help on psql command-line options
  \? variables           show help on special variables
  \h [NAME]              help on syntax of SQL commands, * for all commands

Query Buffer
  \e [FILE] [LINE]       edit the query buffer (or file) with external editor
  \ef [FUNCNAME [LINE]]  edit function definition with external editor
  \ev [VIEWNAME [LINE]]  edit view definition with external editor
  \p                     show the contents of the query buffer
  \r                     reset (clear) the query buffer
  \s [FILE]              display history or save it to file
  \w FILE                write query buffer to file

 

Input/Output
  \i FILE                execute commands from file
  \o [FILE]              send all query results to file or |pipe

Informational
  (options: S = show system objects, + = additional detail)
  \d[S+]                 list tables, views, and sequences
  \d[S+]  NAME           describe table, view, sequence, or index

  \l[+]   [PATTERN]      list databases

 \di[S+] [PATTERN]      list indexes

 \dp     [PATTERN]      list table, view, and sequence access privileges

  \dt[S+] [PATTERN]      list tables
  \dT[S+] [PATTERN]      list data types
  \du[S+] [PATTERN]      list roles
  \dv[S+] [PATTERN]      list views

Connection
  \c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
                         connect to new database (currently "postgres")
  \conninfo              display information about current connection
  \encoding [ENCODING]   show or set client encoding
  \password [USERNAME]   securely change the password for a user

 

 

 

你可能感兴趣的:(postgreSQL)