3

I’m trying to connect to PostgreSQL database that is in the same network with my computer using Java application. When I was using localhost (or 127.0.0.1) all works fine, but when I replaced it with the local IP of my computer, the connection refused error occurred.

I edited the pg_hba.conf file as follows:

    # "local" is for Unix domain socket connections only
    local   all             all                                     trust
    # IPv4 local connections:
    host    all             all            192.168.0.0/16           trust
    host    all             all            127.0.0.1/24             trust
    # IPv6 local connections:
    host    all             all             ::1/128                 trust
    host    all             all             fe80::/10               trust
    # Allow replication connections from localhost, by a user with the
    # replication privilege.
    local   replication     all                                     trust
    host    replication     all             192.168.1.15/24         trust
    host    replication     all             ::1/128                 trust
    host    duplicate       all             fe80::/10               trust

The listen_addresses in the postgresql.conf file is:

    #listen_addresses = ‘*’     # what IP address(es) to listen on;

So I still can not connect to the DB.

When I removed this from the pg_hba.conf

local   all             all                                     trust

The connection refused error occurred event when I used localhost / 127.0.0.1 to connect. Thank you for any help.

1 Answer 1

3

This is a comment:

#listen_addresses = ‘*’ # what IP address(es) to listen on;

Delete the # in front, changing it to:

listen_addresses = ‘*’ # what IP address(es) to listen on;

Restart the postgres server, and everything else is fine.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.