PostgreSQL Getting Started manual, pgsql login to connect to the database.


psql --help

pgsql我们用的命令不多,常用的就那么几个参数,常用的,连接,输入格式和输出格式。 PostgreSQL远程或者本地ip,一般可以不用填写,默认就是localhost或者127.0.0.1

General options:
  -c, --command=COMMAND    run only single command (SQL or internal) and exit
  -d, --dbname=DBNAME      database name to connect to (default: "dev")

Connection options:
  -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: "dev")
  -w, --no-password        never prompt for password
  -W, --password           force password prompt (should happen automatically)


psql -h -Udev  -p 3433 -l

# output
                                 List of databases
    Name    |   Owner    | Encoding | Collation | Ctype |     Access privileges     
 logs       | 123        | UTF8     | C         | C     | 
 postgres   | 123        | UTF8     | C         | C     | 


party_logs=> help
You are using psql, the command-line interface to PostgreSQL.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
party_logs=> \?

help可以查看所有的命令,\?可以查看pgsql commands\h可以查看SQL commands


party_logs=> \h
Available help:


party_logs=> \dp
                                     Access privileges
 Schema |      Name       |   Type   |     Access privileges     | Column access privileges 
 public | logs            | table    |                           | 
 public | logs_log_id_seq | sequence |                           | 
(2 rows)


To reply to the article, please Login or registered