"Psql:could not connect to Server:connection refused" Error while connecting to remote database

Source: Internet
Author: User
Tags psql postgres database

Problem:

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 Ddb_name

This error is occurs:

Psql:could not connect to Server:connection refused are 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 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.

PostgreSQL Ubuntu Psql Centos7
ShareEdit Asked Sep 7 ' at 12:48poonam Anthony4395
Firewall is still blocking port 5432. Check your configs for iptables. –dmitry Savinkov Sep 7 ' at 17:03
@Dmitry I disabled iptables by running sudo ufw disable , but I ' m still getting the same Error.–poonam Anthony Sep 8 ' 10:2 5
Can you try a ' netstat-na|grep 5432 ' and see if PostgreSQL binds to all interfaces? –kometen Dec ' at

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

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

Open file namedpostgresql.conf

sudo vi postgresql.conf

Add this line to the file

listen_addresses = ‘*‘

Then open file namedpg_hba.conf

sudo vi pg_hba.conf

and add this line to the 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 while connecting to remote database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.