问题:

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. java实现的快速排序算法

    快速排序的原理:选择一个关键值作为基准值.比基准值小的都在左边序列(一般是无序的),比基准值大的都在右边(一般是无序的).一般选择序列的第一个元素. 一次循环:从后往前比较,用基准值和最后一个值比较, ...

  2. 跳转到设置页面 与appstory

    //MARK:系统跳到应用设置页面 func systemMySet(){ let url = NSURL(string: UIApplicationOpenSettingsURLString) if ...

  3. android设备中USB转串口demo 下载

    http://files.cnblogs.com/guobaPlayer/testUSB2Serial.apk USB转串口demo程序, 无需驱动,只要手机USB是OTG类型,插上我们的模块即可使用 ...

  4. laravel 日志

    laravel学院的 http://laravelacademy.org/post/195.html 他人博客的 http://www.cnblogs.com/yjf512/p/4173261.htm ...

  5. 图片的 base64 编码

    图片的 base64 编码就是将一幅图片编码成一串字符串,使用该字符串代替图像地址.我们所看到的网页上的图片,都是需要消耗一个 http 请求下载而来的:(所有才有了 csssprites 技术< ...

  6. C++中int转为char 以及int 转为string和string 转int和空格分隔字符串

    1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...

  7. ModelDriven

    功能:  submit 之后显示结果  1.项目结构 2.web.xml <?xml version="1.0" encoding="UTF-8"?> ...

  8. redirect-action

    功能: 点击login , redirect 到hello.jsp 显示 "hello" 点击redirect, redirect 到 error.jsp 显示 "err ...

  9. sql 针对拼接语句的优化

    在日常的开发中尽量少采用拼接语句,但针对多条件联合查询,并有多字段可以偏序的情况下,的确采用拼接语句要方便简单得多,单数据库会因为传入的参数不同而产生不同的计划数,计划数多了,对数据库影响很大. 为了 ...

  10. MySQL 5.5 禁用 innodb

    MySQL 5.5 禁用 innodb 编辑: my.ini 添加: default-storage-engine=MYISAM skip-innodb