In order to be able to connect to my postgresql database from another machine, I had to configure my postgresql.conf file like so:


# - Connection Settings -

listen_addresses = ''                # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)

I tried using but that didn't work. Neither did "localhost". The only way I was able to do make this work is to use the actual IP address of the server. I checked to make sure in my "hosts" file, localhost was defined....

In any case, I am now able to connect from a different server by doing the following:

psql -U test test -h

But now I'm noticing that I cannot log on locally using the following syntax:

psql -U test test -h

The only way to log in locally is

psql -U test test

I tried to change my postgresql.conf file to use "*"... and that let's me log in remotely, but locally, i still cannot use or "localhost" to connect.

How can I set this up so that both my remote logins and my local logins work?

  • Did you try a comma-separated list of address like the comment suggests? 'localhost,'
    – Craig
    Nov 19, 2013 at 20:07

1 Answer 1


I had to edit my pg_hba.conf file:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all               md5
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                trust
#host    replication     postgres            trust
#host    replication     postgres        ::1/128                 trust
host    all             all                md5
host    replication     postgres              trust

I changed the methods from "trust" to "md5" and that's fixed my problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .