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

本文记录了使用HighGo数据库交互终端psql时遇到的问题,包括连接设置、用户名默认值来源及用户权限查看等核心内容。展示了如何通过命令行进行数据库连接尝试,并解释了连接失败的原因。
[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 <hgsql-bugs@highgo.com>.
[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

脚本: #!/bin/bash # Nominatim 自动化部署脚本 (root用户版) set -e # 配置参数 NOMINATIM_DIR="/opt/nominatim" POSTGRES_USER="nominatim_admin" POSTGRES_PASSWORD=$(openssl rand -base64 16) OSM_DATA_URL="https://download.geofabrik.de/europe/monaco-latest.osm.pbf" API_PORT=8080 echo ">>> 正在安装系统依赖..." apt update && apt install -y \ build-essential cmake libboost-dev libexpat1-dev \ zlib1g-dev libxml2-dev libbz2-dev libpq-dev libproj-dev \ postgresql postgresql-contrib postgis postgresql-14-postgis-3 \ apache2 php php-pgsql python3-dotenv python3-psycopg2 python3-requests echo ">>> 配置 PostgreSQL..." sudo -u postgres psql -c "CREATE USER $ POSTGRES_USER WITH PASSWORD '$ POSTGRES_PASSWORD' SUPERUSER;" sudo -u postgres createdb -O $ POSTGRES_USER nominatim sudo -u postgres psql -d nominatim -c "CREATE EXTENSION postgis;" sudo -u postgres psql -d nominatim -c "CREATE EXTENSION hstore;" # 优化 PostgreSQL 配置 cat <<EOF > /etc/postgresql/14/main/conf.d/nominatim.conf shared_buffers = 2GB work_mem = 128MB maintenance_work_mem = 2GB effective_cache_size = 4GB EOF systemctl restart postgresql echo ">>> 编译安装 Nominatim..." mkdir -p $ NOMINATIM_DIR cd $ NOMINATIM_DIR git clone --depth 1 https://github.com/osm-search/Nominatim.git cd Nominatim mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release .. make -j$(nproc) echo ">>> 下载并导入 OSM 数据..." wget $ OSM_DATA_URL -O data.osm.pbf ./utils/setup.php --osm-file data.osm.pbf --all \ --osm2pgsql-cache 2000 \ --threads $(nproc) \ --reverse-only echo ">>> 配置 Apache 服务..." cat <<EOF > /etc/apache2/sites-available/nominatim.conf <VirtualHost *:$ API_PORT> DocumentRoot $ NOMINATIM_DIR/Nominatim/build/website <Directory "$ NOMINATIM_DIR/Nominatim/build/website"> Require all granted AddType text/html .php </Directory> <Files ".php"> SetHandler application/x-httpd-php </Files> </VirtualHost> EOF a2dissite 000-default a2ensite nominatim sed -i "s/Listen 80/Listen $ API_PORT/" /etc/apache2/ports.conf systemctl restart apache2 echo ">>> 安全加固..." # 限制数据库权限 sudo -u postgres psql -c "ALTER USER $ POSTGRES_USER NOSUPERUSER;" chmod 750 $ NOMINATIM_DIR echo ">>> 验证部署..." curl -s "http://localhost:$ API_PORT/search.php?q=Monaco&format=json" | jq . cat <<EOF =============================== Nominatim 部署成功! 访问地址: http://服务器IP:$ API_PORT/search?q=<地址> 数据库用户: $ POSTGRES_USER 数据库密码: $ POSTGRES_PASSWORD 安装目录: $ NOMINATIM_DIR =============================== EOF 在运行后还需要输入参数吗?
最新发布
07-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值