zoukankan      html  css  js  c++  java
  • psql: could not connect to server: No such file or directory&&PGHOST

    由于环境变量 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=# 
  • 相关阅读:
    netty解决TCP的拆包和粘包的解决办法
    HTML图片热区map area的用法
    JWT应用
    React-router4简约教程
    axios中文文档
    如何区分Babel中的stage-0,stage-1,stage-2以及stage-3(一)
    python datetime offset-aware与offset-navie相互转换
    DJango跨域中间键
    Javacript实现倒计时
    CAN协议,系统结构和帧结构
  • 原文地址:https://www.cnblogs.com/EikiXu/p/9705324.html
Copyright © 2011-2022 走看看