Re: custom log. variable %h reports [unknown] - Mailing list pgsql-admin

From Tom Lane
Subject Re: custom log. variable %h reports [unknown]
Date
Msg-id 15173.1453837396@sss.pgh.pa.us
Whole thread Raw
In response to Re: custom log. variable %h reports [unknown]  (Jerry Sievers <gsievers19@comcast.net>)
List pgsql-admin
Jerry Sievers <gsievers19@comcast.net> writes:
> Artem Tomyuk <admin@leboutique.com> writes:
>> log_line_prefix = '===========> %h %u %t %p %x: [%l-1]'    
>> But in logs i see:
>> ===========>  [unknown] 2016-01-26 17:07:46 UTC 1664 0: [1-1]LOG:  connection received: host=192.168.112.181
port=50321

> Postmaster.

Good guess, but actually that log entry is emitted in the new backend
process.  We do know the remote IP at that point (obviously, because
we show it in the message).  But we haven't told elog about it quite
yet.  This seems just dumb.  I think we should switch the order of
these two stanzas in BackendInitialize():

    if (Log_connections)
    {
        if (remote_port[0])
            ereport(LOG,
                    (errmsg("connection received: host=%s port=%s",
                            remote_host,
                            remote_port)));
        else
            ereport(LOG,
                    (errmsg("connection received: host=%s",
                            remote_host)));
    }

    /*
     * save remote_host and remote_port in port structure
     */
    port->remote_host = strdup(remote_host);
    port->remote_port = strdup(remote_port);


BTW, the [unknown] bit is actually coming from %u, and that's
correct because we've not yet identified the user.  AFAICS,
elog just prints nothing for %h when the port->remote_host is
not set yet.

            regards, tom lane


pgsql-admin by date:

Previous
From: Willy-Bas Loos
Date:
Subject: Re: copy a barman snapshot to another backup server
Next
From: Alvaro Herrera
Date:
Subject: Re: pg_dump / pg_restore - TOC.dat file