PostgreSQL的常见参数和技巧

墨墨导读:本文主要详述PostgreSQL的常见参数以及一些技巧。



1. psql命令



1.1 General options


1.1.1- ?


我们可以psql -?或者psql --help看下psql有哪些可用参数:

 
 
[postgres@host01 ~]$ psql --help	
psql is the PostgreSQL interactive terminal.	
Usage:	
  psql [OPTION]... [DBNAME [USERNAME]]	
General options:	
  -c, --command=COMMAND    run only single command (SQL or internal) and exit	
  -d, --dbname=DBNAME      database name to connect to (default: "postgres")	
  -f, --file=FILENAME      execute commands from file, then exit	
  -l, --list               list available databases, then exit	
  -v, --set=, --variable=NAME=VALUE	
                           set psql variable NAME to VALUE	
                           (e.g., -v ON_ERROR_STOP=1)	
  -V, --version            output version information, then exit	
  -X, --no-psqlrc          do not read startup file (~/.psqlrc)	
  -1 ("one"), --single-transaction	
                           execute as a single transaction (if non-interactive)	
  -?, --help[=options]     show this help, then exit	
      --help=commands      list backslash commands, then exit	
      --help=variables     list special variables, then exit	
Input and output options:	
  -a, --echo-all           echo all input from script	
  -b, --echo-errors        echo failed commands	
  -e, --echo-queries       echo commands sent to server	
  -E, --echo-hidden        display queries that internal commands generate	
  -L, --log-file=FILENAME  send session log to file	
  -n, --no-readline        disable enhanced command line editing (readline)	
  -o, --output=FILENAME    send query results to file (or |pipe)	
  -q, --quiet              run quietly (no messages, only query output)	
  -s, --single-step        single-step mode (confirm each query)	
  -S, --single-line        single-line mode (end of line terminates SQL command)	
Output format options:	
  -A, --no-align           unaligned table output mode	
  -F, --field-separator=STRING	
                           field separator for unaligned output (default: "|")	
  -H, --html               HTML table output mode	
  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \pset command)	
  -R, --record-separator=STRING	
                           record separator for unaligned output (default: newline)	
  -t, --tuples-only        print rows only	
  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)	
  -x, --expanded           turn on expanded table output	
  -z, --field-separator-zero	
                           set field separator for unaligned output to zero byte	
  -0, --record-separator-zero	
                           set record separator for unaligned output to zero byte	
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: "postgres")	
  -w, --no-password        never prompt for password	
  -W, --password           force password prompt (should happen automatically)	
For more information, type "\?" (for internal commands) or "\help" (for SQL	
commands) from within psql, or consult the psql section in the PostgreSQL	
documentation.	
	
Report bugs to <[email protected]>.


1.1.2- E


我们可以实验一下-E的效果:

 
 
[postgres@host01 ~]$ psql -E	
psql (11.2)	
Type "help" for help.	
	
postgres=# \c yx	
You are now connected to database "yx" as user "postgres".	
yx=# \d	
********* QUERY **********	
SELECT n.nspname as "Schema",	
  c.relname as "Name",	
  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'table' WHEN 'I' THEN 'index' END as "Type",	
  pg_catalog.pg_get_userbyid(c.relowner) as "Owner"	
FROM pg_catalog.pg_class c	
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace	
WHERE c.re
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值