zoukankan      html  css  js  c++  java
  • “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 command:

    psql -h host_ip -U db_username -d db_name

    This the error that occurs:

    psql: could not connect to server: Connection refused Is the server running on host "" and accepting TCP/IP connections on port 5432?

    1. Postgres installed version is 9.4.
    2. Host operating system : Ubuntu 15.04
    3. Client operating system : Centos 7

    I already tried the following but the issue remains unresolved:

    1. Edited pg_hba.conf file to include

    host all all 0.0.0.0/0 md5

    1. Edited 'postgresql.conf' and changed the listen parameter to

    listen_addresses='*'

    1. Restarted postgres service.
    2. Disabled firewall and iptables on host and client.
    3. I checked by running the psql command locally and it worked.
    4. I tried the second solution given in this question. Running nmap gave me the following output:

    Starting Nmap 6.47 ( http://nmap.org ) at 2015-09-07 18:08 IST Nmap scan report for 10.17.250.250 Host is up (0.0000040s latency). Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 80/tcp open http

    Am I missing something. Hope someone can help.

    shareedit
     
        
    firewall is still blocking port 5432. check your configs for iptables. – Dmitry Savinkov Sep 7 '15 at 17:03
        
    @Dmitry I disabled iptables by running sudo ufw disable, but I'm still getting the same error. – Poonam Anthony Sep 8 '15 at 10:25
        
    Can you try a 'netstat -na|grep 5432' and see if postgresql binds to all interfaces? – kometen Dec 15 '15 at 

    ----------------------------------------------------------------------------

    cd /etc/postgresql/9.x/main/

    open file named postgresql.conf

    sudo vi postgresql.conf

    add this line to that file

    listen_addresses = '*'

    then open file named pg_hba.conf

    sudo vi pg_hba.conf

    and add this line to that file

    host  all  all 0.0.0.0/0 md5

    It allows access to all databases for all users with an encrypted password

    restart your server

    sudo /etc/init.d/postgresql restart
  • 相关阅读:
    spring入门
    mybatis环境配置与入门例子
    wine 魔兽争霸
    不要再使用工具格式化代码!!!
    Android 动画 setVisibility 后出错解决方法
    AbsListView.OnScrollListener 使用注意事项
    linux 配置 wlan 连接
    练习:求完数问题
    重写:求比指定数大且最小的“不重复数”问题
    emacs 快捷键笔记
  • 原文地址:https://www.cnblogs.com/oxspirt/p/6220366.html
Copyright © 2011-2022 走看看