由于环境变量 PGHOST配置不当引起的

postgres@pgdb-> psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.1921"?

若环境变量PGHOST未配置,且psql不加-h命令的时候,则默认使用的是数据库参数unix_socket_directories 的默认值(一般是/tmp)
作为unix-domain-socket路径。

即:psql 相当于 psql -h /tmp

情况1

若环境变量PGHOST未配置,并修改了unix_socket_directories参数,则直接使用psql命令连接会报错:

注:postgres server 是运行状态

postgres@pgdb-> psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.1921"

解决方法:

    1.psql命令必须加 -h 选项 并指定 unix-domain-socket的路径(即unix_socket_directories参数所设置的值)

    2.或者环境变量里添加PGHOST,其值为unix_socket_directories 路径

过程演示

1.无意修改了unix_socket_directories的默认值,并将其改成了任意目录(这里假设将该参数值设置成/home/postgres/pgdata)

2.则下次使用直接使用psql连接时,便会报错:

postgres@pgdb-> psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.1921"? 3.这时,解决方法如下: postgres@pgdb-> psql -h /home/postgres/pgdata
psql (9.5.7)
Type "help" for help. postgres=# 或者在环境变量里添加: export PGHOST=/home/postgres/pgdata 然后应用环境变量,再使用psql直连:
postgres@pgdb-> psql
psql (9.5.7)
Type "help" for help. postgres=#

psql: could not connect to server: No such file or directory&&PGHOST的更多相关文章

  1. 问题解决: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"?

    错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...

  2. 问题解决: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"?

    错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...

  3. psql: could not connect to server: No such file or directory

    postgresql报错: psql: could not connect to server: No such file or directory         Is the server run ...

  4. docker 踩坑笔记之 psql: could not connect to server

    最近在用docker跑rails,也遇到了一些坑,这里记录一下. 首先build项目: docker-compose build 然后就开始报错了: psql: could not connect t ...

  5. “psql: could not connect to server: Connection refused” Error when connecting to remote database

    问题: I am trying to connect to a postgres database installed in a remote server using the following c ...

  6. postgresql connection failure:SQLSTATE[08006] [7] could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

    PHP 程序无法连接到 CentOS 上的PostgreSQL,但是在 CentOS 服务器上却能正常运行 psql, 操作如下:多次重启 PG 数据库后发现 CGI 脚本无法连接数据库,但是可以使用 ...

  7. SSH登录之后运行命令报错的解决办法-- Failed to connect to Mir: Failed to connect to server socket: No such file or directory

    问题描述: Failed to connect to Mir: Failed to connect to server socket: No such file or directory 解决方案: ...

  8. LoadRunner执行过程报错“Failed to connect to server "xxx.xxx.xxx.xxx:xx":[10060] connetion time out”

    执行性能测试过程中,LR报错: Action.c(6):Error -27796: Failed to connect to server "xxx.xxx.xxx.xxx:xx" ...

  9. MySQL忘记密码,或:root密码重置报错:mysqladmin: connect to server at 'localhost' failed的解决方案

    MySQL root密码重置报错:mysqladmin: connect to server at 'localhost' failed的解决方案   1  登陆失败,mysqladmin修改密码失败 ...

随机推荐

  1. Eclipse工具的设置

    1 Eclipse的工作空间和新建工程1.1: 工作空间* 其实就是我们写的源代码所在的目录 1.2: 创建工程(项目)* 右键/Package Explore 空白区/new /Java Proje ...

  2. SWF 文件不能本地访问 只有仅限于文件系统的 SWF 文件

    http://blog.163.com/vituk93@126/blog/static/1709580342012512112757505/ SWF 文件不能被本地访问 不能访问本地 只有仅限于文件系 ...

  3. python, 用filter实现素数

    # _*_ coding:utf-8 _*_ #step1: 生成一个序列def _odd_iter(): n = 1 while True: n = n + 1 yield n #Step2: 定义 ...

  4. c#与C++类型转换网摘

    转载自 C++和C#转换 https://www.cnblogs.com/zjoch/p/4147182.html c#与C++类型转换,网摘 //c++:HANDLE(void   *)       ...

  5. amqp 和 exchange 详细解释

    amqp  的 excange 字面意思是一个交换机.他的任务是吧 消息 分配给消息队列. amqp 的  exchange 有三种,分别是 Direct , fanout 和 toppic.三种. ...

  6. reduceByKey和groupByKey区别与用法

    在spark中,我们知道一切的操作都是基于RDD的.在使用中,RDD有一种非常特殊也是非常实用的format——pair RDD,即RDD的每一行是(key, value)的格式.这种格式很像Pyth ...

  7. vs2013 使用vs2017的localdb

    应用vs203进行MVC开发时,进行数据库初始化的时候,默认使用电脑中高版本的localdb(v12),在修改web.config中的链接串时报错,也无法使能数据库迁移, 解决方法:在数据库初始化之前 ...

  8. 手动增加pe节并修改oep

    一直想学学怎么动动pe文件,学习了几篇文章尤其是寒晨的文章后,自己动手也尝试了一下加节和修改oep,写出来供和我一样菜的一起进步. 一.       增加pe节需要的操作 1.    确定内存中的节的 ...

  9. Java通过webservice接口获取天气信息

    通过SOAP请求的方式获取天气信息并解析返回的XML文件. 参考: http://www.webxml.com.cn/WebServices/WeatherWS.asmx import java.io ...

  10. xcode 添加target