PostgreSQL log_line_prefix Builder
log_line_prefix decides what PostgreSQL writes at the start of every log line: timestamp, process ID, user, database, application, client address, SQLSTATE and more. This tool explains each % escape in a prefix, flags escapes your version ignores, previews a line from a client session and from a background process, writes the postgresql.conf and ALTER SYSTEM lines, and builds a regex with named groups. Paste real log lines to check that the regex splits them correctly. It follows the PostgreSQL 14 to 18 source and runs in your browser.
Do more than postgresql log_line_prefix builder — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Pick a preset or type your own log_line_prefix, and choose the PostgreSQL version. Run SHOW log_line_prefix; to see the current value.
- Read the breakdown and checks: what each escape prints, which parts are empty for background processes, and whether pgBadger can parse it.
- Copy the postgresql.conf or ALTER SYSTEM line, then paste a few real log lines to test the generated regex against them.
Frequently asked questions
What is the default log_line_prefix in PostgreSQL?
Since PostgreSQL 10 the default is '%m [%p] ': a timestamp with milliseconds and time zone, then the process ID in brackets. It does not show the user, database or client, so most teams add %u, %d, %a and %h or %r. Change it in postgresql.conf or with ALTER SYSTEM SET log_line_prefix and SELECT pg_reload_conf(); no restart is needed.
What does %q do in log_line_prefix?
%q prints nothing. It tells background processes such as the checkpointer, autovacuum and WAL writer to stop at that point, because they have no user, database or client. Put session fields (%u, %d, %a, %r, %h, %i) after %q, and keep the timestamp and PID before it, so background lines do not end with empty user= and db= fields.
What log_line_prefix does pgBadger need?
pgBadger needs a time escape (%t, %m or %n) and a process escape (%p or %c). For stderr logs its documentation suggests '%t [%p]: user=%u,db=%d,app=%a,client=%h '. If you use a different prefix, pass the exact same string to pgbadger --prefix so it can parse the lines.
