What value should I set in postgresql.conf to enable the use of "localhost" and "127.0.0.1" and the ip address?

To be able to connect to my postgresql database from another computer, I had to configure the postgresql.conf file as follows:

#------------------------------------------------------------------------------ # 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 did not work. Also there was no "localhost". The only way I was able to do this was to use the actual IP address of the server. I checked to make sure my hosts file was localhost ....

In any case, now I can connect from another server by doing the following:

 psql -U test test -h 10.14.4.4 

But now I notice that I cannot log in 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 this allowed me to log in remotely, but locally I still cannot use 127.0.0.1 or "localhost" to connect.

How can I configure this to work both my remote logins and my local logs?

Thanks.

EDIT 1

This is 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 
+6
source share
2 answers

You need to modify the pg_hba.conf file, see http://www.postgresql.org/docs/8.2/static/auth-pg-hba-conf.html

0
source

I had to edit the pg_hba.conf file to use MD5, not trust. Here's 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 in remotely with an IP address and log in locally using an IP address.

0
source

Source: https://habr.com/ru/post/958421/


All Articles