Re: custom log. variable %h reports [unknown]

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jerry Sievers <gsievers19(at)comcast(dot)net>
Cc: Artem Tomyuk <admin(at)leboutique(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: custom log. variable %h reports [unknown]
Date: 2016-01-26 19:43:16
Message-ID: 15173.1453837396@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Jerry Sievers <gsievers19(at)comcast(dot)net> writes:
> Artem Tomyuk <admin(at)leboutique(dot)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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Clécio Anderson 2016-01-26 20:21:05 Re: pg_dump / pg_restore - TOC.dat file
Previous Message Willy-Bas Loos 2016-01-26 18:51:45 Re: copy a barman snapshot to another backup server