Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aO9WP-0003gw-Rb for pgsql-admin@arkaria.postgresql.org; Tue, 26 Jan 2016 19:43:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aO9WP-0008Df-B0 for pgsql-admin@arkaria.postgresql.org; Tue, 26 Jan 2016 19:43:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aO9WO-0008DZ-UY for pgsql-admin@postgresql.org; Tue, 26 Jan 2016 19:43:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aO9WM-0004w3-4O for pgsql-admin@postgresql.org; Tue, 26 Jan 2016 19:43:23 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u0QJhGc5015590; Tue, 26 Jan 2016 14:43:16 -0500 From: Tom Lane To: Jerry Sievers cc: Artem Tomyuk , pgsql-admin@postgresql.org Subject: Re: custom log. variable %h reports [unknown] In-reply-to: <86bn88urt4.fsf@jerry.enova.com> References: <86bn88urt4.fsf@jerry.enova.com> Comments: In-reply-to Jerry Sievers message dated "Tue, 26 Jan 2016 12:19:35 -0600" Date: Tue, 26 Jan 2016 14:43:16 -0500 Message-ID: <15173.1453837396@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org Jerry Sievers writes: > Artem Tomyuk 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 -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin