Re: psql connection via localhost or 127.0.0.1

From: Edoardo Panfili <edoardo(at)aspix(dot)it>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: psql connection via localhost or 127.0.0.1
Date: 2014-11-06 15:48:15
Message-ID: 545B983F.9050505@aspix.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Il 06/11/14 16:08, Tom Lane ha scritto:
> Edoardo Panfili <edoardo(at)aspix(dot)it> writes:
>> I am using postgres 9.4beta3 (Debian jessie)
>> this is my pg_hba.conf
>> ----------------------
>> local all postgres peer
>> local all all md5
>> host all all 127.0.0.1/32 md5
>> host all all ::1/128 md5
>> ----------------------
>> but if I use psql to connect via tcp to the server (on the same machine)
>> I can see two differente behaviours if I use "localhost" or "127.0.0.1"
>> If I understand correctly the first two lines are useful only for Unix
>> sockets and not for tcp-ip connection.
> Yeah. On modern Linux distros it's quite likely that "localhost" is
> resolving as IPv6 ::1, not 127.0.0.1, but in neither case would it match
> your "local" lines. In any case, your first connection attempt is
> definitely not connecting over a Unix socket because we never use SSL
> with Unix sockets.
ok, thank you.
>
> I can think of two plausible theories:
>
> 1. The postmaster isn't actually using the pg_hba.conf you think it is.
> (Maybe you modified the file and forgot to do a "pg_ctl reload"?)
another way on my test machine:
/etc/init.d/postgresql stop
/etc/init.d/postgresql start

>
> 2. You have a "service file" active that is capturing the server name
> "localhost" and redefining it to mean something other than the obvious
> meaning.
> http://www.postgresql.org/docs/9.3/interactive/libpq-pgservice.html
>
> A useful test would be to try "psql -h ::1" and see which way that
> behaves. If it does the same thing as "-h localhost" then we can
> eliminate the service-file theory.
-------- connection via ::1----------------
$ psql -h ::1 -U postgres
Inserisci la password per l'utente postgres:
----------------------------------------
same as for 127.0.0.1

thank you
Edoardo

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Edoardo Panfili 2014-11-06 15:53:03 Re: psql connection via localhost or 127.0.0.1
Previous Message John R Pierce 2014-11-06 15:47:09 Re: psql connection via localhost or 127.0.0.1