2

I just recently install PostgreSQL on our server via SSH. The installation went successful, until the time I tried to connect to it using pgAdmin on my Windows machine.I received this kind of error:

could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "xxx.xxx.xxx.xxx" and accepting TCP/IP connections on port 5432?

xxx.xxx.xxx.xxx = my server's public IP.

The docs suggest this can be fixed by setting the value of listen_addresses = '*' in the /etc/postgresql/9.1/main/postgresql.conf. I did that but still it won't let me.

additional error came up

FATAL: no pg_hba.conf entry for host "xxx.xx.xxx.xxx", user "postgres", database "postgres", SSL on FATAL: no pg_hba.conf entry for host "xxx.xx.xxx.xxx", user "postgres", database "postgres", SSL off

xxx.xx.xxx.xxx = my IP address.

What seems to be I'm missing?

0

3 Answers 3

5

Things that could block a postgres connection:

  1. misconfigured listen_address in postgresql.conf
  2. selinux (?)
  3. iptables
  4. pg_hba.conf (although this should cause a different error, not server doesn't listen)

Can you connect to the server locally, if you ssh in and run psql?

On our internal dev servers, I just turn off selinux and iptables. This is a bad idea from a security standpoint, but it might serve as a temporary step to help you narrow down where the problem is.

3
  • remotely via SSH, I can managed to do psql under postgres user. I can't only access it if I use pgAdmin which is installed on my Windows machine. Sep 5, 2012 at 18:11
  • I can now connect to postgres via pgAdmin, however I hardcoded my IP address host all all 122.55.37.1XX/32 md5.How can I make it like a wildcard that would fit that IP address category? Sep 6, 2012 at 6:53
  • 1
    @LeandroGarcia: With IP addressses, you need to think "bitmask", not "wildcard". It depends on how many IP addresses you want to accept connections from, and what those last two digits are. For example, 122.55.37.100/29 would cover the range 122.55.37.97 to 122.55.37.102; 122.55.37.130/29 would cover 122.55.37.129 to 122.55.37.134; 122.55.37.166/27 would cover 122.55.37.161 to 122.55.37.190. (I think. Google "online subnet calculator", or something along those lines for help with bitmasks.) Sep 6, 2012 at 11:16
2

You might need to change more than one configuration file. In your case, you probably need to edit pg_hba.conf, too. Search that file for "non-local connections".

I like to keep configuration files under version control. It's easier to recover from mistakes that way.

You probably need to restart the PostgreSQL server after making those changes.

7
  • But all those pertains to local, local all postgres peer , local all all peer , host all all 127.0.0.1/32 md5 , host all all ::1/128 md5 Sep 5, 2012 at 18:13
  • @Leandro Garcia: if only local unix sockets and 127.0.0.1 or ::1/128 (ie localhost) are currently being allowed, that may be the problem. You will need to add a line with the subnet your client machine is using. ie 192.168.0.0/16 etc. Sep 5, 2012 at 18:31
  • I'm confused, my IPv4 is 192.168.0.100, then default gateway is 192.168.0.1. How do I add this? Sep 5, 2012 at 18:35
  • @Leandro Garcia: lookup CIDR notation for details. you can simply add 192.168.0.100/32 to only add your current ip address. If that address changes, you may want 192.168.0.0/24 to allow anyone in 192.168.0.x to connect to your database server. Sep 5, 2012 at 18:38
  • So if i were to add this, I ended up with something like this : local all all 192.168.0.0/24 md5.But this didn't work, an error stating "Invalid authentication method 192.168.0.0/24" Sep 5, 2012 at 18:42
1
  • After changing listen_addresses settings on the server, make sure to restart the PostgreSQL server (send SIGHUP to the postmaster process, with kill -HUP, etc).
  • Make sure that postgresql.conf port is set to 5432
  • Make sure that if a firewall is running on the server, that port 5432 is open for connections coming from the window's (client) machine you are using
  • Check pg_hba.conf to make sure that the subnet of your client machine is given access
  • Try using psql locally
1
  • @Catcall @Joshua Berry - I managed to do this however I hardcoded my IP address : host all all 122.55.37.1XX/32 md5 how can I make it like a wildcard that would fit that IP address category? Sep 6, 2012 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.