问题:

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. NVIC

    1中断:每一个中断都会对应一个服务程序 2NVIC 他的做用是负责中断优先级管理 3IP bit[7:4]每一个中断都有一个IP寄存器,用于设置中断相关的属性 AIRCR[10:8]只一个AIRCR寄 ...

  2. hdu 5901 Count primes 素数计数模板

    转自:http://blog.csdn.net/chaiwenjun000/article/details/52589457 计从1到n的素数个数 两个模板 时间复杂度O(n^(3/4)) #incl ...

  3. 1.Office 365系列(-)

    //来源:http://www.cnblogs.com/JessZhou/p/3470654.html 首先从Office 365开始. Office 365是微软云计划的一部分,主要包括sharep ...

  4. [阿当视频]WEB组件学习笔记

    — 视频看完了,自定义事件还不懂,等完全懂了再更新并完成整篇案例 1. JS分层和组件的种类浏览器底层包括HTML CSS JS(DOM/BOM/Style/Canvas 2D/WebGl/SVG) ...

  5. bigdata之hadoop and spark

    目前正在学习Hadoop和spark之类的东西,一个月把Hadoop的基础东西过了一遍,但是感觉好动都没跟上老师的课程,哪位前辈了解这方面的东西希望给指点迷津.接下来我们还要学习spark和nosql ...

  6. LeetCode 280. Wiggle Sort C#

    Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] < ...

  7. /home 和 /root

    /root     Linux超级权限用户root的家目录./home 如果我们建立一个用户,用户名是"xx",那么在/home目录下就有一个对应的/home/xx路径,用来存放用 ...

  8. 使用MegaCli工具,在线调整raid配置

    公司hadoop平台采购了一批浪潮服务器,2个系统盘,12个数据盘.先想的用直通的raid卡免得再做单盘raid0麻烦,结果这批机器配的卡也不支持裸盘使用,咨询浪潮客服,说可以使用JBOD的模式进行, ...

  9. 以Jar形式为Web项目提供资源文件

    以Jar形式为Web项目提供资源文件 http://www.webjars.org/ Web前端使用了越来越多的JS或CSS如jQuery, Backbone.js 和Twitter Bootstra ...

  10. HDU 5831 Rikka with Parenthesis II

    如果左括号数量和右括号数量不等,输出No 进行一次匹配,看匹配完之后栈中还有多少元素: 如果n=2,并且栈中无元素,说明是()的情况,输出No 如果n=2,并且栈中有元素,说明是)(的情况,输出Yes ...