3

I am starting with PostGIS and there is an error when trying to connect through a TCP/IP connection. What I have done is: installed PostGre 9.3 in my PC, then installed PostGIS 2.3 for postGre 9.3, then I tested the database in my computer using localhost and all worked fine, then I wanted to connect to the database form another computer that is in the same network (from now on, PC2).. I read many forums and then modify pg_hba.conf trying to allow PC2 to connect. I just couldn´t.

Default file:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

And this is how I modified it:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             10.0.0.99               md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

note that the new value is 10.0.0.99, which is the IP address of PC2.

Can anyone help?

2
  • 1
    putting a line listen_addresses = '*' in postgresql.conf and restart your server Nov 19 '14 at 13:10
  • yes, I forgot to tell that it was set to '*'. Thanks! Nov 19 '14 at 14:11
4

Was dealling with same problem just few hours ago.

I think you should add a CIDR mask length (/32 for a single address - Wikipedia details) in ip-address section:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             10.0.0.99/32               md5
.
.
.

After saving pg_hba.conf file you should restart server with new configuration just run pgAdmin and choose Reload configuration in Tools menu: enter image description here

4
  • Thank you! It solved a part of the problem. Before the change you propose pgAdminIII couldn't connect to the database, and after the change it was solved. But when I try to connect from PC2, I can't. Basic question, when I connect from my PC I use "localhost", what should I write when ask for "Server"?? Nov 19 '14 at 14:55
  • Do you have a firewall enabled? If so, port 5432 traffic passing through it? Once the route is clear, you need to specify the server hostname from other hosts.
    – Vince
    Nov 19 '14 at 15:55
  • Let's say PC is your machine with database, PC2 is 10.0.0.99 machine. Try pinging PC ip address from PC2. If everthing is ok then on PC2 you should set database connection as: host= PC_ip_address dbname=database_name(on PC) user=database_owner(PC) and pass=users_password.
    – jzol
    Nov 19 '14 at 21:44
  • Solved! Thank you all. You were right Vince, it was the firewall. I disable it and then, as jzol said, I used my local IP address as "server", and that's it. Now, I have to see how to keep firewall up, but allowing port 5432 passing through it. Thank you again! Nov 21 '14 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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