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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 向下取整和向上取整的符号_python向上取整函数

    向下取整和向上取整的符号_python向上取整函数向上取整,运算称为Ceiling,用数学符号⌈⌉(上有起止,开口向下)表示,。向下取整,运算称为Floor,用数学符号⌊⌋(下有起止,开口向上)表示。注意,向上取整和向下取整是针对有浮点数而言的;若整数向上取整和向下取整,都是整数本身。四舍五入:更接近自己的整数;把小数点后面的数字四舍五入 即:如被舍去部分的头一位数字小于五,则舍去;如大于等于五,则被保留…

    2025年8月24日
    17
  • 【推荐】Java内存管理系列文章

    勿在流沙筑高台,出来混迟早要还的。做一个积极的人编码、改bug、提升自己我有一个乐园,面向编程,春暖花开!谢谢你的阅读,如果您觉得这篇博文对你有帮助,请点赞或者喜欢,让更多的人看到!祝你每天开心愉快!不管做什么,只要坚持下去就会看到不一样!在路上,不卑不亢!博客首页 : http://blog.csdn.net/u010648555愿你我在人生的路上能都变成最好的自己,能…

    2022年2月28日
    40
  • inputstream类型的变量需要关闭吗_input type

    inputstream类型的变量需要关闭吗_input typeinputStream的作用是用来表示那些从不同数据源产生输入的类。这些数据源包括    1字节数组    2String对象   3文件   4管道,工作方式与实际管道相似,即一端输入,从另一端输出    5一个由其他种类的流组成的序列,以便我们可以将他们收集合并到一个流内   6其他数据源,如internet连接等 每一种数据源都有相

    2022年9月21日
    4
  • 为低端浏览器定义原型方法matchAll[通俗易懂]

    为低端浏览器定义原型方法matchAll[通俗易懂]String.prototype.matchAll=function(reg){letmatchArr=[];letmatch;while((match=reg.exec(this))!==null){matchArr.push(match);}returnmatchArr;};

    2022年7月23日
    9
  • 一键生成代码生成器(怎么一键生成表格)

    分享代码自动生成工具,穿插swagger,主要是目的,还是提高开发效率

    2022年4月17日
    50
  • 配置AAA认证和授权

    配置AAA认证和授权一、目的1、掌握AAA认证的工作原理。2、掌握使用CiscoSecureACS服务器实现AAA认证授权的方法。二、网络拓扑三、认证部分实验要求配置和测试本地和基于认证服务器的AAA认证。1、在R1上创建本地帐号,配置本地AAA认证登录console和VTY。2、配置和测试本地和基于认证服务器的AAA认证。1、在R1上创建本地帐号(用户名:A…

    2022年5月2日
    111

发表回复

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

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