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’; ——重启生效
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。