what value to set in postgresql.conf to enable use of "localhost" and "127.0.0.1" and ip address?

postgresql

Solution

I had to edit the pg_hba.conf file to use MD5, not trust. This is what the final file looks like:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            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        127.0.0.1/32            trust
#host    replication     postgres        ::1/128                 trust
host    all             all             10.14.4.0/24             md5
host    replication     postgres        10.14.0.0/16              trust

Now I can log on remotely specifying IP address, and log on locally using IP address too.

Problem

In order to be able to connect to my postgresql database from another machine, I had to configure my postgresql.conf file like so: ``` #------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - listen_addresses = '10.14.4.4' # 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 127.0.0.1 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 10.14.4.4 ``` But now I'm noticing that I cannot log on locally using the following syntax: ``` psql -U test test -h 127.0.0.1 ``` 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 127.0.0.1 or "localhost" to connect. How can I set this up so that both my remote log ins and my local log ins work? Thanks. EDIT 1 Here's what my pg_hba.conf file looks like: ``` # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # 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 127.0.0.1/32 trust #host replication postgres ::1/128 trust host all all 10.14.4.0/24 trust host replication postgres 10.14.0.0/16 trust ```

Original source