PostgreSQL CSV Log (csvlog) Columns Explained, With Examples
Published
One CSV row per server log message when log_destination includes csvlog: 26 columns in a fixed order, with no header row — when, which account and database, the client host:port, session and process, the severity and SQLSTATE code, the message with its detail and hint, the statement that caused an error, and the application name.
Official documentation: PostgreSQL 16: Error Reporting and Logging (20.8.4 Using CSV-Format Log Output) · PostgreSQL 16: Appendix A. PostgreSQL Error Codes
Sample record
2024-01-15 09:00:01.007 UTC,app_user,appdb,10001,10.0.0.10:52001,65a4f410.2711,1,SELECT,2024-01-15 09:00:00 UTC,2/10001,0,LOG,00000,statement: SELECT id FROM users WHERE active=true LIMIT 10,,,,,,,,,,client backend,,0 From the LogTriage parser test corpus — synthetic data, no real hosts or users.
Field reference
| Field | Type | Meaning | Why it matters for security |
|---|---|---|---|
| log_timee.g. 2024-01-15 14:30:01.415 UTC | timestamp | PostgreSQL: "time stamp with milliseconds", in the log_timezone setting. | Check log_timezone before lining this up with other logs; it is often a local zone. |
| user_namee.g. postgres | string | The database role; for a failed login, the role the client asked for. | Failed logins for postgres from outside addresses are password guessing against the superuser. |
| database_namee.g. production | string | The database the session connected to, or tried to. | Connections to databases an account never uses are worth a look. |
| process_ide.g. 12348 | number | The backend process that wrote the message; every connection gets its own. | Groups all messages of one connection when session_id is not at hand. |
| connection_frome.g. 185.220.101.42:55004 | host:port | PostgreSQL: "client host:port number". A Unix-socket connection shows [local] without a port; background processes (autovacuum, checkpointer) leave it empty. | The address that connected — any public address here means the server is reachable from the internet. |
| session_ide.g. 65a54171.303c | string | PostgreSQL: "a quasi-unique session identifier, consisting of two 4-byte hexadecimal numbers (without leading zeros) separated by a dot. The numbers are the process start time and the process ID". | Follow one session from authentication to its last statement. |
| session_line_nume.g. 4 | number | The number of the message within its session, starting at 1. | Gaps show messages that were filtered out or lost. |
| command_tage.g. authentication | string | PostgreSQL: "type of session's current command" — authentication during login, otherwise SELECT, INSERT, DROP TABLE and so on. | authentication with FATAL is a failed login; DROP TABLE and ALTER ROLE are changes to look at. |
| virtual_transaction_ide.g. 3/12349 | string | The virtual transaction ID (backend ID / local transaction number). | Groups statements of one transaction. |
| transaction_ide.g. 67891 | number | The regular transaction ID, or 0 when none was assigned (read-only work). | Non-zero means the statement wrote something. |
| error_severitye.g. FATAL | string | The message level: DEBUG, LOG, INFO, NOTICE, WARNING, ERROR, FATAL or PANIC. FATAL ends the session; statement and connection logging use LOG. | FATAL with 28P01 or 28000 is a refused login; ERROR with 42501 is a refused privilege. |
| sql_state_codee.g. 28P01 | five characters | The SQLSTATE error code from PostgreSQL's error code table: 00000 successful_completion, 28P01 invalid_password, 28000 invalid_authorization_specification, 42501 insufficient_privilege, 42P01 undefined_table. | Count 28P01 per connection_from for guessing, and 42501 per user for privilege probing. |
| messagee.g. connection authorized: user=postgres database=production application_name=psql | string | The primary message. With log_statement it is "statement: " followed by the SQL; with log_connections, "connection received" and "connection authorized" lines. | The statement text is here for logged statements — pg_shadow, pg_authid, COPY … TO PROGRAM and DROP are the ones to search. |
| detaile.g. Connection matched file | string | The error message detail. For a failed login it names the pg_hba.conf line that matched. | Shows which access rule let an outside address try a password at all. |
| querye.g. SELECT * FROM users | string | PostgreSQL: "user query that led to the error (if any and enabled by log_min_error_statement)". | The statement that was refused — what someone tried to do. |
| application_namee.g. psql | string | The application_name the client set, if any (psql, pgAdmin 4, a driver name). | Clients set it themselves; an interactive tool where only your application connects is still worth a look. |
| backend_typee.g. client backend | string | The kind of process: client backend for connections, or background processes such as autovacuum worker and checkpointer. | Filter to client backend for user activity. |
Have one of your own records? Paste it into the log line explainer and each field is explained from this table, with times, codes and addresses decoded — in your browser.
What it records
PostgreSQL writes every server log message — connections, authentication results, errors, and statements when statement logging is on — to its log destinations. With csvlog, each message is one CSV row whose columns the manual lists in order: “time stamp with milliseconds, user name, database name, process ID, client host:port number, session ID, per-session line number, command tag, session start time, virtual transaction ID, regular transaction ID, error severity, SQLSTATE code, error message, error message detail, hint, internal query that led to the error (if any), character count of the error position therein, error context, user query that led to the error (if any and enabled by log_min_error_statement), character count of the error position therein, location of the error in the PostgreSQL source code (if log_error_verbosity is set to verbose), application name, backend type, process ID of parallel group leader, and query id.”
What reaches the log depends on configuration. Failed logins are always logged as FATAL. Successful logins need log_connections, statements need log_statement (ddl, mod or all), and refused statements are logged with their text when log_min_error_statement is at ERROR (the default).
The malicious sample shows three failed passwords for the postgres superuser from one outside address, a successful login from the same address a few seconds later, a read of the password hashes in pg_shadow and a DROP TABLE audit_logs in that session, and a second address refused a read of users (42501).
Where to get it
- Files.
log_directoryunder the data directory (or/var/log/postgresqlon Debian-based systems), one.csvfile per rotation. - Into a table.
COPY postgres_log FROM '/path/postgresql.csv' WITH csv;with the manual’s table definition;file_fdwreads it in place. - Managed services. Amazon RDS and Aurora, Cloud SQL and Azure Database for PostgreSQL export the server log to their logging services, usually in the stderr text format rather than CSV.
- jsonlog. PostgreSQL 15 and later can write the same information as JSON (
log_destination = 'jsonlog').
# Failed logins per client address
awk -F, '$12 == "FATAL" && $13 == "28P01" {split($5, a, ":"); print a[1]}' postgresql.csv | sort | uniq -c | sort -rn
Parsing pitfalls
- No header row. Map columns by position; older versions have fewer trailing columns (23 before PostgreSQL 13).
- Quoted multi-line fields. Messages and statements can contain commas, quotes (doubled) and newlines; use a real CSV reader, not
split(',')— theawkabove only works because the first thirteen columns never contain commas. - Time zone. log_time uses log_timezone, written as an abbreviation (UTC, CET, EST).
- Statements in two places. Logged statements are in
message(“statement: …”); statements that caused an error are inquery. - Passwords in statements.
CREATE ROLE … PASSWORD '…'is logged in full with log_statement — the manual warns logged statements “might reveal sensitive data and even contain plaintext passwords”.
Detection ideas
- Password guessing: FATAL 28P01 counts per connection_from, and a
connection authorizedfrom the same address afterwards. - Exposure: any public address in connection_from on a database that should only serve your application servers.
- Credential reads: statements touching
pg_shadow,pg_authidor application credential tables. - Destructive or evasive statements: DROP, TRUNCATE,
ALTER ROLE … SUPERUSER,COPY … TO PROGRAM, changes to logging settings. - Privilege probing: bursts of 42501 for one role.
The free browser analyzer reads PostgreSQL csvlog files (with or without a header row), the stderr format and jsonlog, and runs these checks locally.
Sending PostgreSQL to an LLM
One megabyte of this format is about 515,927 tokens on current Claude models and 368,243 on GPT models, measured with the models' own tokenizers — so a gigabyte sent raw to Claude Sonnet 5.5 costs about $1,032 in input tokens alone (prices of 2026-10-24). Estimate your own volume →
Frequently Asked Questions
- How do I enable CSV logging in PostgreSQL?
- Set log_destination = 'csvlog' (or 'stderr,csvlog') and logging_collector = on in postgresql.conf and restart; files appear in log_directory with a .csv extension. To record logins and statements, also set log_connections = on and log_statement to ddl, mod or all, depending on the volume you can keep.
- Why does my PostgreSQL CSV log have no header row?
- csvlog never writes one. The 26 columns always come in the documented order: log_time, user_name, database_name, process_id, connection_from, session_id and so on to query_id (backend_type was added in PostgreSQL 13, leader_pid and query_id in 14). The manual gives a CREATE TABLE postgres_log definition with these names so the file can be loaded with COPY … WITH csv.
- What does SQLSTATE 28P01 mean in PostgreSQL logs?
- invalid_password: the client gave the wrong password for the role, logged as FATAL with the message password authentication failed for user and, in the detail, the pg_hba.conf line that matched. 28000 (invalid_authorization_specification) is the code when no pg_hba.conf line allows the connection at all.
- How do I see failed logins and the statements that followed?
- Filter error_severity FATAL and sql_state_code 28P01 to count guesses per connection_from, then look for a connection authorized message from the same address and follow its session_id: with log_statement enabled, each statement of that session is a LOG row with the same session_id and increasing session_line_num.
Analyze a PostgreSQL file in your browser
The free analyzer detects this format, parses every field above and flags attack patterns — the file never leaves your machine. For threat-intel enrichment and an AI-written incident report, run it through LogTriage.
Investigating something right now? LogTriage checks every address in the file against threat intelligence and writes the incident report: 10 analyses a month free. The incident pack adds the in-depth AI analysis and files up to 100 MB: 25 analyses for $19, one payment, no subscription. Pricing
How this page was made. The official definitions, field names and examples on it are copied by script from the sources it links and re-checked against them on every build. The investigation advice was drafted with AI from those sources and passed a separate review before publishing. What is checked, and how · found a mistake? [email protected]