DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Reporting and Logging / Where to Log

log_filename

Sets the file name pattern for log files.

  • Default: postgresql-%Y-%m-%d_%H%M%S.log
  • Type: string
  • Applies: Reload

In plain words

A name pattern for the log files. Codes like %Y (year), %m, %d, %H or %a (weekday) are filled in with the time the file is opened.

The pattern decides how many different files you get: the default makes a new, uniquely named file each time; postgresql-%a.log reuses seven names, one per weekday.

For DBAs and operators

Escapes are strftime() codes evaluated in log_timezone. Without any escape all output goes to one file name. If the pattern ends in .log, csvlog and jsonlog files get the same name with .csv / .json; otherwise those suffixes are appended.

Common patterns:

  • postgresql-%Y-%m-%d_%H%M%S.log (default): a new name at each rotation, so files pile up forever; you need external cleanup.
  • postgresql-%a.log + log_rotation_age = 1d + log_truncate_on_rotation = on: a self-cleaning one-week ring.
  • postgresql-%H.log + log_rotation_age = 1h: a 24-hour ring.

If the name produced at a rotation already exists, the logger appends to it unless truncation applies. A size-based rotation (log_rotation_size) that produces the same name as the current file (a pattern without %H%M%S, or two rotations within one second) just keeps appending to that file, so include %H%M%S if you rotate by size.

SELECT pg_current_logfile();

How to change it

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

See it in context

Logger (logging collector)

Related parameters

log_directory log_truncate_on_rotation log_rotation_age log_rotation_size logging_collector log_timezone

All Reporting and Logging parameters