sql - Postgres not allowing localhost but works with 127.0.0.1 -


postgres not accepting connection if -h localhost works if -h 127.0.0.1

[root@5d9ca0effd7f opensips]# psql -u postgres -h localhost -w password user postgres: psql: fatal:  ident authentication failed user "postgres" [root@5d9ca0effd7f opensips]# psql -u postgres -h 127.0.0.1 -w password user postgres: psql (8.4.20) type "help" help.  postgres=# 

my /var/lib/pgsql/data/pg_hba.conf

# type  database    user        cidr-address          method  # "local" unix domain socket connections local                                        trust local                                        ident # ipv4 local connections: host                    127.0.0.1/32          trust host                    127.0.0.1/32          ident # ipv6 local connections: host                    ::1/128               ident 

if add following line postgres service failed start:

host                   localhost             ident host                   localhost             trust 

wwhat wrong there?

update

my /etc/hosts file:

[root@5d9ca0effd7f opensips]# cat /etc/hosts 172.17.0.2      5d9ca0effd7f 127.0.0.1       localhost ::1     localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 

in pg_hba.conf, first match counts. per documentation:

the first record matching connection type, client address, requested database, , user name used perform authentication. there no "fall-through" or "backup": if 1 record chosen , authentication fails, subsequent records not considered. if no record matches, access denied.

note reversed order:

host                    127.0.0.1/32          trust host                    127.0.0.1/32          ident 

but:

host                   localhost             ident host                   localhost             trust 

well, if "add" lines wrote, there should not effect @ all. if replace lines, there is.

in first case, trust authentication method, open door policy. per documentation:

postgresql assumes can connect server authorized access database whatever database user name specify (even superuser names)

but in second case ident authentication method, has set work.

if using outdated version 8.4, go old manual 8.4. aware 8.4 has reached eol in 2014 , not supported more? consider upgrading current version.

more:


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -