DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Reporting and Logging / What to Log

log_hostname

Logs the host name in the connection logs. By default, connection logs only show the IP address of the connecting host. If you want them to show the host name you can turn this on, but depending on your host name resolution setup it might impose a non-negligible performance penalty.

  • Default: off
  • Type: bool
  • Applies: Reload

In plain words

Normally the log shows a client's IP address. With this on, PostgreSQL looks up the host name for each new connection and logs that instead. Convenient to read, but each lookup takes time and a slow DNS server slows down every connection.

For DBAs and operators

Affects %h/%r in log_line_prefix, the log_connections "connection received" line, log_disconnections, and pg_stat_activity.client_hostname (which is NULL when off). Captured with on, connecting via 127.0.0.1:

… client=localhost,localhost(53884) … ERROR: division by zero

The reverse lookup happens in the new backend during connection setup, before authentication; it uses the system resolver (with its timeouts), so a broken or slow DNS turns into slow logins. When pg_hba.conf uses host names, PostgreSQL resolves them anyway, independent of this setting.

Recommendation: keep it off and resolve addresses at analysis time; or make sure a local caching resolver is in place.

How to change it

Change in postgresql.conf or ALTER SYSTEM, then run SELECT pg_reload_conf().

See it in context

Client authentication Client backend

Related parameters

log_connections log_line_prefix log_disconnections

All Reporting and Logging parameters