psql连接报错connections on Unix domain socket “/pgsql/data/.s.PGSQL.5432“?
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.54322.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.54323.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参考
https://www.cnblogs.com/ios9/p/15544892.html  
https://blog.csdn.net/lyp13696402570/article/details/120769088?spm=1001.2014.3001.5501 
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号