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

PostgreSQL数据库psql连接报错connections on Unix domain socket “/pgsql/data/.s.PGSQL.5432“?问题现象[postgres@lyp~]$pg_ctl-D/pgsql/data/startwaitingforservertostart….2021-10-1501:42:31.606CST[32453]LOG:redirectinglogoutputtologgingcollectorprocess2021-10-1501:42:31.606CST[32453]HINT:Futurelogoutputwillappearin…

大家好,又见面了,我是你们的朋友全栈君。

 问题现象 

[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 ~]$ 

解决办法

所以解决以上错误有两个办法:

1、删除环境变量的export PGHOST=/pgsql/data

2、设置参数unix_socket_directories=’/pgsql/data’;        ——重启生效

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/150983.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • pycharm怎么打包成exe文件_pycharm怎么保存py文件

    pycharm怎么打包成exe文件_pycharm怎么保存py文件使用Pycharm将多个py文件打包成一个可运行并且可安装文件第一步:安装pyinstaller第二步:打包生成exe文件第三步:造成一个类似安装程序的东西第一步:安装pyinstaller先打开命令行,打开pycharm在左下角:打包程序前提要安装pyinstaller:(如果本文档下面要使用那些命令使用不了的话建议卸载pyinstaller再返回这一步使用命令行再装一次)第二步:…

    2022年8月27日
  • curl 命令

    curl 命令

    2022年1月13日
  • python中的eval函数的用法_isnan函数

    python中的eval函数的用法_isnan函数eval函数在Python中具有非常重要的地位,熟练的使用eval函数能够为我们的Python编程提供很多的便利之处。在本文中我将详细记录eval函数在Python中的使用方法及它带来便利时带来的一些其他危害,希望您阅读完本文后能够有所收获。欢迎在文章下方留言共同交流学习。

    2022年10月23日
  • Linux应用开发自学之路

    Linux应用开发自学之路 前言    在「关于我 」那篇博文里,朋友们应该知道了我不是科班出身,是由机械强行转行到Linux应用开发方向。下面我就详细向大家介绍自己这一路上的转行历程,希望对大家有所启发。 我是学机械专业的,对于机械专业我还是很感兴趣,而且当年这个专业也是我自己选择的。本科时成绩没排第一,但也排专业前列。硕士时成绩一直是专业第一,还拿过国家奖学金。由此可见,我还是挺热爱机…

    2022年5月22日
  • 关于pdb文件

    关于pdb文件关于pdb文件当程序在VS上编译时,程序所依赖的所有动态链接库(dll文件)也会被编译,编译过程中每个dll都会产生一个pdb文件,又称为“符号文件”,是一个存储数据的信息文件,其包含dll库在编译过程的某些调试信息,例如程序中所用到的全局变量、局部变量、函数名以及他们的入口地址等。当使用VS调试程序时,会默认加载你的程序以及程序依赖的dll库产生的所有pdb文件,但是结…

    2022年6月2日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号