public inbox for [email protected]  
help / color / mirror / Atom feed
Capturing both IP address and hostname in the log
6+ messages / 5 participants
[nested] [flat]

* Capturing both IP address and hostname in the log
@ 2025-04-10 12:22  Tefft, Michael J <[email protected]>
  0 siblings, 2 replies; 6+ messages in thread

From: Tefft, Michael J @ 2025-04-10 12:22 UTC (permalink / raw)
  To: [email protected] <[email protected]>

The documentation for log_hostname says:
log_hostname (boolean)
By default, connection log messages only show the IP address of the connecting host. Turning this parameter on causes logging of the host name as well. Note that depending on your host name resolution setup this might impose a non-negligible performance penalty. This parameter can only be set in the postgresql.conf file or on the server command line.

https://www.postgresql.org/docs/14/runtime-config-logging.html

We have set log_hostname ON and we get hostname reported - but we do not get IP address. We would like to capture both.
Since the doc says "Turning this parameter on causes logging of the host name *as well*" we were hoping we would capture both, but we are not getting what we expect.

Is there a way to capture both IP address and hostname in the log messages? Or must we choose "one or the ootehr"?

Thanks,
Mike Tefft

(We are using PG14 and PG16, but the docs say the same thing, as does PG17)


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Capturing both IP address and hostname in the log
@ 2025-04-10 15:22  Adrian Klaver <[email protected]>
  parent: Tefft, Michael J <[email protected]>
  1 sibling, 1 reply; 6+ messages in thread

From: Adrian Klaver @ 2025-04-10 15:22 UTC (permalink / raw)
  To: Tefft, Michael J <[email protected]>; [email protected] <[email protected]>

On 4/10/25 05:22, Tefft, Michael J wrote:
> The documentation for log_hostname says:
> 
> log_hostname (boolean)
> 
> By default, connection log messages only show the IP address of the 
> connecting host. Turning this parameter on causes logging of the host 
> name as well. Note that depending on your host name resolution setup 
> this might impose a non-negligible performance penalty. This parameter 
> can only be set in the postgresql.conf file or on the server command line.
> 
> https://www.postgresql.org/docs/14/runtime-config-logging.html 
> <https://www.postgresql.org/docs/14/runtime-config-logging.html;
> 
> We have set log_hostname ON and we get hostname reported – but we do not 
> get IP address. We would like to capture both.
> 
> Since the doc says “Turning this parameter on causes logging of the host 
> name **as well**” we were hoping we would capture both, but we are not 
> getting what we expect.
> 
> Is there a way to capture both IP address and hostname in the log 
> messages? Or must we choose “one or the ootehr”?

I see the same thing. It seems either or.

> 
> Thanks,
> 
> Mike Tefft
> 
> (We are using PG14 and PG16, but the docs say the same thing, as does PG17)
> 

-- 
Adrian Klaver
[email protected]







^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Capturing both IP address and hostname in the log
@ 2025-04-10 16:00  Tom Lane <[email protected]>
  parent: Adrian Klaver <[email protected]>
  0 siblings, 2 replies; 6+ messages in thread

From: Tom Lane @ 2025-04-10 16:00 UTC (permalink / raw)
  To: Adrian Klaver <[email protected]>; +Cc: Tefft, Michael J <[email protected]>; [email protected]; Melanie Plageman <[email protected]>

[ moving to -hackers ]

Adrian Klaver <[email protected]> writes:
> On 4/10/25 05:22, Tefft, Michael J wrote:
>> We have set log_hostname ON and we get hostname reported – but we do not 
>> get IP address. We would like to capture both.
>> Is there a way to capture both IP address and hostname in the log 
>> messages? Or must we choose “one or the ootehr”?

> I see the same thing. It seems either or.

Melanie recently committed a patch (9219093ca) that purports to
generalize our log_connections logging ability:

    Convert the boolean log_connections GUC into a list GUC comprised of the
    connection aspects to log.
    
    This gives users more control over the volume and kind of connection
    logging.
    
    The current log_connections options are 'receipt', 'authentication', and
    'authorization'. The empty string disables all connection logging. 'all'
    enables all available connection logging.

I wonder if it'd be reasonable to remove the separate log_hostname GUC
and fold it into this infrastructure, and while doing so make it
possible to log either or both of the client IP address and hostname.
(For that matter, I think there is interest in being able to capture
the server IP address too, cf 3516ea768.  You might wish to log the
IP address only once, not in every log line.)

			regards, tom lane






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Capturing both IP address and hostname in the log
@ 2025-04-10 16:33  David G. Johnston <[email protected]>
  parent: Tefft, Michael J <[email protected]>
  1 sibling, 0 replies; 6+ messages in thread

From: David G. Johnston @ 2025-04-10 16:33 UTC (permalink / raw)
  To: Tefft, Michael J <[email protected]>; +Cc: [email protected] <[email protected]>

On Thu, Apr 10, 2025 at 5:22 AM Tefft, Michael J <[email protected]>
wrote:

> The documentation for log_hostname says:
>
> log_hostname (boolean)
>
> By default, connection log messages only show the IP address of the
> connecting host. Turning this parameter on causes logging of the host name
> as well. Note that depending on your host name resolution setup this might
> impose a non-negligible performance penalty. This parameter can only be set
> in the postgresql.conf file or on the server command line.
>
>
>
> https://www.postgresql.org/docs/14/runtime-config-logging.html
>
>
>
Yeah, the wording really should be more like:

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index fea683cb49..c545fee6c9 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7614,10 +7614,11 @@ local0.*    /var/log/postgresql
       </term>
       <listitem>
        <para>
-        By default, connection log messages only show the IP address of the
-        connecting host. Turning this parameter on causes logging of the
-        host name as well.  Note that depending on your host name
resolution
-        setup this might impose a non-negligible performance penalty.
+        By default, for TCP/IP-originated connections, the identifier of
the host
+        making the connection is its IP address.  Turning this parameter
on tells
+        the system to record the resolved host name instead.  Note that
depending
+        on your host name resolution setup this might impose a
non-negligible
+        performance penalty.
         This parameter can only be set in the
<filename>postgresql.conf</filename>
         file or on the server command line.
        </para>


Both the connection logging routine and log_line_prefix %h / %r simply
report the "identifier of the host making the connection".

David J.


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Capturing both IP address and hostname in the log
@ 2025-04-10 16:35  David G. Johnston <[email protected]>
  parent: Tom Lane <[email protected]>
  1 sibling, 0 replies; 6+ messages in thread

From: David G. Johnston @ 2025-04-10 16:35 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Adrian Klaver <[email protected]>; Tefft, Michael J <[email protected]>; [email protected]; Melanie Plageman <[email protected]>

On Thu, Apr 10, 2025 at 9:00 AM Tom Lane <[email protected]> wrote:

> [ moving to -hackers ]
>
> Adrian Klaver <[email protected]> writes:
> > On 4/10/25 05:22, Tefft, Michael J wrote:
> >> We have set log_hostname ON and we get hostname reported – but we do
> not
> >> get IP address. We would like to capture both.
> >> Is there a way to capture both IP address and hostname in the log
> >> messages? Or must we choose “one or the ootehr”?
>
> > I see the same thing. It seems either or.
>

cross-posting to -hackers now that it is here.

v19 plans aside the existing wording is incorrect (just here, other places
correctly point out the either-or aspect of the output).

The wording really should be more like:

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index fea683cb49..c545fee6c9 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -7614,10 +7614,11 @@ local0.*    /var/log/postgresql
       </term>
       <listitem>
        <para>
-        By default, connection log messages only show the IP address of the
-        connecting host. Turning this parameter on causes logging of the
-        host name as well.  Note that depending on your host name
resolution
-        setup this might impose a non-negligible performance penalty.
+        By default, for TCP/IP-originated connections, the identifier of
the host
+        making the connection is its IP address.  Turning this parameter
on tells
+        the system to record the resolved host name instead.  Note that
depending
+        on your host name resolution setup this might impose a
non-negligible
+        performance penalty.
         This parameter can only be set in the
<filename>postgresql.conf</filename>
         file or on the server command line.
        </para>


Both the connection logging routine and log_line_prefix %h / %r simply
report the "identifier of the host making the connection".

David J.


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Capturing both IP address and hostname in the log
@ 2025-05-20 15:48  Melanie Plageman <[email protected]>
  parent: Tom Lane <[email protected]>
  1 sibling, 0 replies; 6+ messages in thread

From: Melanie Plageman @ 2025-05-20 15:48 UTC (permalink / raw)
  To: Tom Lane <[email protected]>; +Cc: Adrian Klaver <[email protected]>; Tefft, Michael J <[email protected]>; [email protected]

On Thu, Apr 10, 2025 at 12:00 PM Tom Lane <[email protected]> wrote:

> Melanie recently committed a patch (9219093ca) that purports to
> generalize our log_connections logging ability:
>
>     Convert the boolean log_connections GUC into a list GUC comprised of
> the
>     connection aspects to log.
>
>     This gives users more control over the volume and kind of connection
>     logging.
>
>     The current log_connections options are 'receipt', 'authentication',
> and
>     'authorization'. The empty string disables all connection logging.
> 'all'
>     enables all available connection logging.
>
> I wonder if it'd be reasonable to remove the separate log_hostname GUC
> and fold it into this infrastructure, and while doing so make it
> possible to log either or both of the client IP address and hostname.
> (For that matter, I think there is interest in being able to capture
> the server IP address too, cf 3516ea768.  You might wish to log the
> IP address only once, not in every log line.)


Seems reasonable to me. I'd be willing to move such a thing forward but
would want to see the feature requestors' specific desired behavior (e.g.
an option for each of hostname, client ip address, and server address?).
Also, if they write a WIP patch at least to config.sgml, it would also help
me gauge how serious of a request it is or, rather, how satisfactory a
solution a log_connections option is.

Perhaps there are people who absolutely love log_hostname and don't want to
see it deprecated as a separate GUC?

I also think folding in log_disconnections as a "disconnection" option
makes sense. I do have some anxiety that a very long list of options will
anger users -- but I suppose that ship mostly sailed.

- Melanie


^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2025-05-20 15:48 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-04-10 12:22 Capturing both IP address and hostname in the log Tefft, Michael J <[email protected]>
2025-04-10 15:22 ` Adrian Klaver <[email protected]>
2025-04-10 16:00   ` Tom Lane <[email protected]>
2025-04-10 16:35     ` David G. Johnston <[email protected]>
2025-05-20 15:48     ` Melanie Plageman <[email protected]>
2025-04-10 16:33 ` David G. Johnston <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox