问题解决:psql: could not connect to server: No such file or directory Is the server running locally and ...

错误提示:

psql: could not connect to server: No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

 

 出现该问题的很多,以下是目前碰到的几种情况,之后碰到继续补充:

1.删除了/tmp路径中的.s.PGSQL.5432 与.s.PGSQL.5432.lock文件

 解决:重启数据库 $sudo service postgresql restart 

 

2.修改监听端口:之前用5434监听,后来改为5432,数据库启动,但是psql无法进入数据库,通过psql -p 5432可以进入。

 解决:安装时配置了端口PGPORT。修改~/.bash_profile或/etc/profile文件中的端口指定。

 

3.修改了postgresql.conf 中的unix_socket_directories

分析见两篇博文:
http://francs3.blog.163.com/blog/static/40576727201332594924829/
http://blog.csdn.net/huguangshanse00/article/details/40413549

 

引用其中:
"先来看看 socket 文件 "/tmp/.s.PGSQL.1921",其中 1921 是 pg 的端口号;

socket 文件可以通过postgresql.conf 文件以下参数配置:

#unix_socket_directory = ''
#unix_socket_permissions = 0777

备注:其中参数 unix_socket_directory 用来配置 socket 文件的目录,默认是 /tmp 目录参数 

unix_socket_permissions 用来设置 socket 文件的权限。"
        
解决方法:指定host,用psql -h 连接 

 

转载于:https://www.cnblogs.com/feixiablog/p/7142022.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
出现该错误的原因可能是 PostgreSQL 服务器没有在指定的端口或 Unix 域套接字文件上运行。您可以按照以下步骤来解决问题: 1. 检查 PostgreSQL 服务器是否正在运行。您可以使用以下命令检查: ``` ps -ef | grep postgres ``` 如果 PostgreSQL 服务器正在运行,则应该会看到类似以下的输出: ``` postgres 12345 1 0 10:00 ? 00:00:01 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf ``` 其中 12345 是 PostgreSQL 服务器进程的 PID。 2. 检查 PostgreSQL 服务器是否在指定的端口上运行。您可以使用以下命令检查: ``` netstat -an | grep 2345 ``` 如果 PostgreSQL 服务器正在监听指定的端口,则应该会看到类似以下的输出: ``` tcp 0 0 127.0.0.1:2345 0.0.0.0:* LISTEN ``` 3. 检查 PostgreSQL 服务器是否在指定的 Unix 域套接字文件上运行。您可以使用以下命令检查: ``` ls -l /tmp/.s.PGSQL.2345 ``` 如果 PostgreSQL 服务器正在监听指定的 Unix 域套接字文件,则应该会看到类似以下的输出: ``` srwxrwxrwx 1 postgres postgres 0 10月 1 10:00 /tmp/.s.PGSQL.2345 ``` 如果文件不存在,则说明 PostgreSQL 服务器没有在该 Unix 域套接字文件上运行。 如果 PostgreSQL 服务器正在运行,并且在指定的端口或 Unix 域套接字文件上监听连接,则您可以尝试使用默认端口(5432)连接到服务器,或通过指定 Unix 域套接字文件的完整路径来连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值