PostgreSQL運維—psql連接報錯socket錯誤
PostgreSQL運維—psql連接報錯socket錯誤
問題現象
[postgres@lyp ~]$ pg_ctl -D /pgsql/data/ start
waiting for server to start....2021-10-15 01:42:31.606 CST [32453] LOG: redirecting log output to logging collector process
2021-10-15 01:42:31.606 CST [32453] HINT: Future log output will appear in directory "pg_log".
done
server started
[postgres@lyp ~]$ psql
psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/pgsql/data/.s.PGSQL.5432"?
[postgres@lyp ~]$
問題分析
查看log日志
[postgres@lyp pg_log]$ tail -100f postgresql-2021-10-15_014231.csv 2021-10-15 01:42:31.606 CST,,,32453,,61686c07.7ec5,1,,2021-10-15 01:42:31 CST,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log destination ""csvlog"".",,,,,,,"","postmaster" 2021-10-15 01:42:31.606 CST,,,32453,,61686c07.7ec5,2,,2021-10-15 01:42:31 CST,,0,LOG,00000,"starting PostgreSQL 13.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit",,,,,,,,,"","postmaster" 2021-10-15 01:42:31.608 CST,,,32453,,61686c07.7ec5,3,,2021-10-15 01:42:31 CST,,0,LOG,00000,"listening on IPv6 address ""::1"", port 5432",,,,,,,,,"","postmaster" 2021-10-15 01:42:31.608 CST,,,32453,,61686c07.7ec5,4,,2021-10-15 01:42:31 CST,,0,LOG,00000,"listening on IPv4 address ""127.0.0.1"", port 5432",,,,,,,,,"","postmaster" 2021-10-15 01:42:31.610 CST,,,32453,,61686c07.7ec5,5,,2021-10-15 01:42:31 CST,,0,LOG,00000,"listening on Unix socket ""/tmp/.s.PGSQL.5432""",,,,,,,,,"","postmaster" 2021-10-15 01:42:31.612 CST,,,32455,,61686c07.7ec7,1,,2021-10-15 01:42:31 CST,,0,LOG,00000,"database system was shut down at 2021-10-15 01:42:16 CST",,,,,,,,,"","startup" 2021-10-15 01:42:31.613 CST,,,32453,,61686c07.7ec5,6,,2021-10-15 01:42:31 CST,,0,LOG,00000,"database system is ready to accept connections",,,,,,,,,"","postmaster"
? 日志中看到socket在:/tmp/.s.PGSQL.5432,而psql卻在找/pgsql/data/.s.PGSQL.5432
查看環境變量
[postgres@lyp ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH export PGHOME=/opt/pgsql13.2 export PGDATA=/pgsql/data export PGHOST=/pgsql/data export PGUSER=postgres export PGPORT=5432 export PATH=$HOME/bin:$PGHOME/bin:$PATH export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH [postgres@lyp ~]$
查看參數
unix_socket_directories
[postgres@lyp ~]$ cat /pgsql/data/postgresql.conf | grep unix_socket_directories #unix_socket_directories = '/tmp' # comma-separated list of directories [postgres@lyp ~]$
解決辦法
所以解決以上錯誤有兩個辦法:
- 刪除環境變量的export PGHOST=/pgsql/data
- 設置參數unix_socket_directories=’/pgsql/data’; ——重啟生效
「喜歡這篇文章,您的關注和贊賞是給作者最好的鼓勵」
關注作者
【版權聲明】本文為墨天輪用戶原創內容,轉載時必須標注文章的來源(墨天輪),文章鏈接,文章作者等基本信息,否則作者和墨天輪有權追究責任。如果您發現墨天輪中有涉嫌抄襲或者侵權的內容,歡迎發送郵件至:contact@modb.pro進行舉報,并提供相關證據,一經查實,墨天輪將立刻刪除相關內容。




