问题:

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.

asked Sep 7 '15 at 12:48
 
    
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

“psql: could not connect to server: Connection refused” Error when connecting to remote database的更多相关文章

  1. could not connect to server: Connection refused (0x0000274D/10061)

    Oracle Linux 6.8 PostgreSQL Server IP: 192.168.10.220 Windows 7 x64 pgAdmin Custom Port IP: 192.168. ...

  2. [nginx] connect() failed (111: Connection refused) while connecting to upstream, client: 101.18.123.107, server: localhost,

    nginx一直报错, 2016/12/02 10:23:19 [error] 1472#0: *31 connect() failed (111: Connection refused)while c ...

  3. nginx访问502 gateway,*1 connect() failed (111: Connection refused) while connecting to upstream

    安装好nginx,php环境后,配置虚拟主机,结果访问后就报502 gateway,查看日志文件后,显示错误如下: 2019/04/29 16:24:39 [error] 19433#19433: * ...

  4. nginx 报错 connect() failed (111: Connection refused) while connecting to upstream

    公司网站搬迁到新服务器后,发现站点访问不了,network里面提示502,查看相关的server配置,感觉没有什么问题,经过测试发现txt.html.等非php文件能够直接访问,也就是php访问不了, ...

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

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

  6. nginx 解决 connect() failed (111: Connection refused) while connecting to upstream,

    嗯哼,刚装了个ubuntu的lnmp,我的天啊,踩的坑比我脂肪还多了 比如刚装完的时候访问显示502, 也不知道什么问题,就去看了一下nginx日志  /var/log/nginx/error.log ...

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

  8. 使用phpmailer插件发邮件失败提示:SMTP -> ERROR: Failed to connect to server: Connection timed out (110) smtp connect() failed;

    一个邮件发送问题,整整弄了我一周时间,起因是这样的,之前弄的一个网站,需要在邮箱里面认证之后才可以注册成功.网站上线了差不多一年之后,客户突然跟我说,网站不能注册了,然后我就查看了一下代码. 发现报这 ...

  9. 解决connect() failed (111: Connection refused) while connecting to upstream

    使用nginx时, 有可能遇到connect() failed (111: Connection refused) while connecting to upstream的问题. 如果upstrea ...

随机推荐

  1. Unity性能优化——LOD技术

    LOD,中文名多层次细节,是游戏中最常用的技术,它按照模型的位置和重要程度决定物体渲染的资源分配,降低非重要物体的面数和细节度,从而获得高效率的渲染运算.今天我们来实现使用它来做一个简单的优化例子. ...

  2. Elastarchsearch安装搭建(一)

    Elasticsearch是一个实时分布式搜索和分析引擎.一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全 ...

  3. anroid平台指纹方案

    神盾的FingerPrint方案 在Java层,神盾主要提供如下几个包: egistec.fingerauth.api.FPAuthListeners; egistec.fingerauth.api. ...

  4. matlab里textread出现错误“Trouble reading floating point number from file (row 1, field 1)”

    matlab里textread出现错误“Trouble reading floating point number from file (row 1, field 1)” 解决办法:traindata ...

  5. Jsp中out.println()与System.out.println()的区别

    第一次上Web实验课时咱写了一个jsp程序: <% System.out.println("Hello The World"); %> 然后放在浏览器下运行,结果是这样 ...

  6. JDOM与DOM主要有两方面不同

    我这丝毫没有吐槽的意思哟,只是想说作为一个合格的程序员大家最起码需要做到思维严谨这点,在有能力的情况下对用户体验能提点建议最好.自己写的代码一定要经过严格测试再交付,不要指望测试人员帮你测试再去修改, ...

  7. C#调用托管C++类(DLL)

    毕设是做一个网络摄像头的相关应用.界面用WPF,图像处理部分是OpenCV.没用EmguCV的原因是国内EmguCV的资料相对比较少,EmguCV虽然提供了Winform的控件,在做UI上有一定优势, ...

  8. iOS 导航栏 不透明

    UINavigationBar.appearance().translucent = false UINavigationBar.appearance().barStyle = UIBarStyle. ...

  9. Cron表达式的详细用法

    字段 允许值 允许的特殊字符 秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1-31 , - * ? / L W C 月份 1-12 或者 JAN- ...

  10. AMD规范

    common.js主要语法就是 var math=require('math'); math.add(2,3); require()用于加载模块就行了. 二行math.add(2, 3),在第一行re ...