由于环境变量 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. 使用 pkg 打包分发 nodejs 应用

    pkg 是一个很不错的跨平台 nodejs 应用打包工具,使用此工具,我们只需要给与用户提供一个简单的 可执行文件就可以了,同时代码也是二进制的,提高了代码的安全性 备注:测试demo 很简单,也比较 ...

  2. jupyter命令把.ipynb文件转化为.py文件

    jupyter nbconvert --to script *.ipynb 就能把当前文件夹下面的所有的.ipynb文件转化为.py文件

  3. windows 8,关闭随意窗体都提示“已停止工作”的解决的方法

           电脑用的好好的,突然出现了关闭随意窗体都提示"已停止工作",每次都是这样.想想也就是偶尔优化一下,近期也没有改动过什么系统设置呀,突然想到昨晚JLink_V8固件丢失 ...

  4. mvn+spring+webapp模板

    idea新建项目,选择maven-archetype-webapp 在main目录下创建java  resource 文件夹,赋予特殊文件夹 pom.xml 添加 <!--Spring框架核心库 ...

  5. es中级部分知识点总结

    --------------------------------------------------------------- 搜索开始-------------------------------- ...

  6. Scrapy 设置请求头

    爬虫的过程有些网站设置反盗链,需要我们在请求头中添加下,修改settings.py文件中添加 DEFAULT_REQUEST_HEADERS = { 'Accept': 'text/html,appl ...

  7. 多层级sql查询

    SELECT ( SELECT ) FROM t_app_user WHERE parent_user_id = t.user_id /*多层级,t.user_id */ ) AS directCou ...

  8. Centos 7 systemctl和防火墙firewalld命令

    今天自己在Hyper-v下搭建三台Linux服务器集群,用于学习ELKstack(即大数据日志解决技术栈Elasticsearch,Logstash,Kibana的简称),下载的Linux版本为cen ...

  9. ML: 聚类算法R包-网格聚类

    网格聚类算法 optpart::clique optpart::clique CLIQUE(Clustering In QUEst)是一种简单的基于网格的聚类方法,用于发现子空间中基于密度的簇.CLI ...

  10. linux(ubuntu)下安装phantomjs

    1.安装phantomjs ubuntu下sudo apt-get install phantomjs下载的不能用 —-下载程序文件 到官网下载 1.安装phantomjs —-下载程序文件 wget ...