由于环境变量 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. C# to il 9 Properties and Indexers(属性和索引器)

    A field is simply a memory location, whereas, a property is a collection of methods. Aproperty is re ...

  2. Space Shooter 学习

    using UnityEngine; using System.Collections; /// <summary> /// 背景滚动 /// </summary> publi ...

  3. JavaScript 中 this的指向

    this 一方面便利了让大家在JS开发当, 但是另一方面让开发者头痛的是不清楚this 指代什么. 指向全局Window: <script> console.log(this); < ...

  4. SelectDataTable

    项目地址 :  https://github.com/kelin-xycs/SelectDataTable SelectDataTable 一个 用 C# 实现的 用 Sql select DataT ...

  5. 装饰模式Decorator Pattern

    1.主要优点 装饰模式的主要优点如下: (1) 对于扩展一个对象的功能,装饰模式比继承更加灵活性,不会导致类的个数急剧增加. (3) 可以对一个对象进行多次装饰,通过使用不同的具体装饰类以及这些装饰类 ...

  6. 利用js获取客户端ip的方法

    1. 通过script标签引入url 比如如下代码: <script type="text/javascript" src="http://pv.sohu.com/ ...

  7. 弱网测试—Network-Emulator-Toolkit工具

    参考别人网址:http://blog.csdn.net/no1mwb/article/details/53638681 弱网测试,属于健壮性测试:怎么样去做弱网测试呢? 一.安装弱网测试工具-Netw ...

  8. MOSSE(DSST)类和KCF类中滤波器推导结果不一致的解释

    首先要说明,DSST//BMVC2014类的CF是从MOSSE//CVPR2010模型得到的,是从信号的角度考虑问题,该类CF直接认为信号和滤波器之间存在相关的关系 而KCF//TPAMI2015类C ...

  9. 高级java必会系列一:常用线程池和调度类

    众所周知,开启线程2种方法:第一是实现Runable接口,第二继承Thread类.(当然内部类也算...)常用的,这里就不再赘述. 一.线程池 1.newCachedThreadPool (1)缓存型 ...

  10. ulimit设置内存限制是否有效

    如何使用ulimit限制物理内存 限制物理内存 $ ulimit -m 512000 经测试,无效. 限制物理内存不起作用,ulimit不支持限制物理内存,可见man ulimit手册 -m The ...