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进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
👍
2年前

评论
有用
2年前

评论
您好,您的文章已入选合格奖,10墨值奖励已经到账请查收!
❤️我们还会实时派发您的流量收益。
3年前

评论
我有时候在自己环境懒得去改参数,直接建个软链
3年前

1
或者,保留PGHOST,同时修改参数unix_socket_directories="."
3年前

1
相关阅读
外国CTO也感兴趣的开源数据库项目——openHalo
小满未满、
999次阅读
2025-04-21 16:58:09
9.9 分高危漏洞,尽快升级到 pgAdmin 4 v9.2 进行修复
严少安
373次阅读
2025-04-11 10:43:23
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
358次阅读
2025-04-15 14:48:05
openHalo问世,全球首款基于PostgreSQL兼容MySQL协议的国产开源数据库
严少安
340次阅读
2025-04-07 12:14:29
转发有奖 | PostgreSQL 16 PGCM高级认证课程直播班招生中!
墨天轮小教习
164次阅读
2025-04-14 15:58:34
SQL 优化之 OR 子句改写
xiongcc
110次阅读
2025-04-21 00:08:06
融合Redis缓存的PostgreSQL高可用架构
梧桐
104次阅读
2025-04-08 06:35:40
PostgreSQL拓展PGQ实现解析
chirpyli
97次阅读
2025-04-07 11:23:17
PostgreSQL的dblink扩展模块使用方法
szrsu
84次阅读
2025-04-24 17:39:30
Mysql/Oracle/Postgresql快速批量生成百万级测试数据sql
hongg
84次阅读
2025-04-07 15:32:54