暂无图片
暂无图片
1
暂无图片
暂无图片
1
暂无图片

psql连接报错connections on Unix domain socket “/pgsql/data/.s.PGSQL.5432“?

2296

1. 现象

# 直接psql  连接异常
postgres@s2ahumysqlpg01-> psql
psql: error: could not connect to server: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/u01/postgresql/data_bak/.s.PGSQL.5432"?

# psql -h 127.0.0.1 可以连接成功
psql: option requires an argument -- 'h'
Try "psql --help" for more information.
postgres@s2ahumysqlpg01-> psql -h 127.0.0.1
psql (12.4)
Type "help" for help.

postgres=# 

复制

2.问题分析

2.1 检查 pg_hba.conf

cat   pg_hba.conf
# "local" is for Unix domain socket connections only
local   all             all                                     trust

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
host    replication     repluser        192.168.1.0/24         md5
host    all             all             192.168.1.0/24         md5
host    all             all             0.0.0.0/24          md5

#无异常

复制

2.2 检查参数文件

postgres@s2ahumysqlpg01-> cat postgresql.conf postgresql.auto.conf |grep socket
#unix_socket_directories = '/tmp'       # comma-separated list of directories
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation

#默认路径未改动 ,但是 缺指向"/u01/postgresql/data_bak/.s.PGSQL.5432"?
怀疑是环境变量的问题
复制

2.3 松果文件 路径

# 检查并没有该文件 
ll /u01/postgresql/data_bak/.s.PGSQL.5432  
ll  /tmp/.s.PGSQL.5432
复制

2.4 检查环境变量

cat   .bash_profile 
PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH
export PS1="$USER@`/bin/hostname -s`-> " 
export PGPORT=5432 

export PGDATA=/u01/postgresql/data_bak
export LANG=en_US.utf8 
export PGHOME=/u01/postgresql/pg12 
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH 
export DATE=`date +"%Y%m%d%H%M"` 
export PATH=$PGHOME/bin:/u01/mysql/app/bin:$PATH:. 
export MANPATH=$PGHOME/share/man:$MANPATH 
export PGHOST=$PGDATA 
export PGDATABASE=postgres 
#export PATH=/home/postgres/pgbackrest/bin:$PATH:.
alias rm='rm -i' 

# 发现设置了PGHOST 
复制

3. 处理

3.1 注释环境变量 PGHOST ,并使期生效

cat   .bash_profile 
PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export PS1="$USER@`/bin/hostname -s`-> " 
export PGPORT=5432 
export PGDATA=/u01/postgresql/data_bak
export LANG=en_US.utf8 
export PGHOME=/u01/postgresql/pg12 
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH 
export DATE=`date +"%Y%m%d%H%M"` 
export PATH=$PGHOME/bin:/u01/mysql/app/bin:$PATH:. 
export MANPATH=$PGHOME/share/man:$MANPATH 
#export PGHOST=$PGDATA 
export PGDATABASE=postgres 
alias rm='rm -i' 


# 使环境变量生效
 . .bash_profile 

# 检查 
postgres@s2ahumysqlpg01-> env | grep PGHOST
postgres@s2ahumysqlpg01-> echo $PGHOST

postgres@s2ahumysqlpg01-> 
复制

3.3 检查文件

# 检查文件是否存在
postgres@s2ahumysqlpg01-> ll /tmp/.s.PGSQL.5432
srwxrwxrwx. 1 postgres postgres 0 Feb 24 13:18 /tmp/.s.PGSQL.5432
复制

3.3 重启数据库并测试

# 重启数据库 路径指向了  /tmp/.s.PGSQL.5432
postgres@s2ahumysqlpg01-> pg_ctl restart  -D /u01/postgresql/data_bak
waiting for server to shut down....... done
server stopped
waiting for server to start....LOG:  Auto detecting pg_stat_kcache.linux_hz parameter...
LOG:  pg_stat_kcache.linux_hz is set to 500000
LOG:  starting PostgreSQL 12.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44.0.3), 64-bit
LOG:  listening on IPv4 address "0.0.0.0", port 5432
LOG:  listening on IPv6 address "::", port 5432
LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "log".
 done
server started

# psql 连接测试,问题解决
postgres@s2ahumysqlpg01-> psql 
psql (12.4)
Type "help" for help.

postgres=# quit
复制

参考

www.cqdba.cn
https://www.cnblogs.com/ios9/p/15544892.html
https://blog.csdn.net/lyp13696402570/article/details/120769088?spm=1001.2014.3001.5501

最后修改时间:2022-03-15 19:51:31
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论

墨天轮福利君
暂无图片
3年前
评论
暂无图片 0
您好,您的文章已入选合格奖,10墨值奖励已经到账请查收! ❤️我们还会实时派发您的流量收益。
3年前
暂无图片 点赞
评论