psql --help输出中的default user值的来源

[highgo432@abc ~]$ env | grep PG
PGPORT=5432
PGUSER=u_lei_aa   ---->>>注意此处
PGHOME=/data/highgo/4.3.2
PGDATA=/data/highgo/4.3.2/data
[highgo432@abc ~]$ psql--help
-bash: psql--help: command not found
[highgo432@abc ~]$ psql --help
psql is the HighGo Database 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: "u_lei_aa")
  -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: "u_lei_aa") ---->>>注意此处
  -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 HighGo Database
documentation.

Report bugs to <[email protected]>.
[highgo432@abc ~]$ psql -d highgo
Password: 
致命错误:  28P01: 用户 "u_lei_aa" Password 认证失败
详细信息:  与Connection相匹配的文件行位于 pg_hba.conf 80: "local   all             all                                     md5"
psql: 致命错误:  28P01: 用户 "u_lei_aa" Password 认证失败
[highgo432@abc ~]$ psql -d highgo -U u_lei
Password for user u_lei: 
psql (4.3.2)

PSQL: Release 4.3.2
Connected to:
HighGo Database V4.3 Standard Edition Release 4.3.2 - 64-bit Production

Type "help" for help.

highgo=# \duS_
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 u_lei     | Superuser, Create role, Create DB, Replication, Bypass RLS | {}              ---->>>注意此处

highgo=# \duS+
                                          List of roles
 Role name |                         Attributes                         | Member of | Description 
-----------+------------------------------------------------------------+-----------+-------------
 u_lei     | Superuser, Create role, Create DB, Replication, Bypass RLS | {}        | 

highgo=# 


结论:psql --help中的  -U, --username=USERNAME  database user name (default: "XXXX"),这个XXXX值来自环境变量$PGUSER

猜你喜欢

转载自blog.csdn.net/msdnchina/article/details/80531721