View PostgreSQL Logs Live in a Browser (jsonlog & Slow Queries) β
To inspect PostgreSQL errors and slow queries in real time without grepping multi-line plain-text logs, enable PostgreSQL 15+'s native jsonlog destination (log_destination = 'jsonlog' with logging_collector = on), set log_min_duration_statement to your latency threshold, and stream the .json log file into Logdy with logdy follow. Every PostgreSQL log entry becomes a structured row in your browser with clickable facets for error_severity, dbname, user, and state_code.
Definition: PostgreSQL
jsonlog(introduced in PostgreSQL 15) is a built-inlog_destinationoption that serializes each server log entry as a single-line JSON object containing typed fields such astimestamp,error_severity,dbname,user,state_code,message, andstatement.
Step 1: Enable jsonlog and Slow-Query Logging in postgresql.conf β
According to the official PostgreSQL documentation (Β§19.8 Error Reporting and Logging), logging_collector must be set to on for PostgreSQL to emit jsonlog files, and changing logging_collector requires a PostgreSQL restart.
Add or update these settings in postgresql.conf:
# Required for jsonlog output (restart PostgreSQL after changing logging_collector)
logging_collector = on
log_destination = 'jsonlog'
# Where log files are written (relative to PGDATA unless absolute)
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d.log'
# Log any query taking 200ms or longer (-1 disables; 0 logs every statement)
log_min_duration_statement = 200
# Optional: log lock waits longer than deadlock_timeout
log_lock_waits = onTip: You can keep both plain-text and JSON logs during migration by setting
log_destination = 'stderr, jsonlog'. PostgreSQL automatically appends.jsonto the JSON log filename and records the active file path in$PGDATA/current_logfiles.
Restart PostgreSQL to activate logging_collector, or reload if logging_collector was already on:
# Restart required when enabling logging_collector for the first time
sudo systemctl restart postgresql
# Reload is enough for later changes to log_min_duration_statement
sudo -u postgres psql -c "SELECT pg_reload_conf();"Find the Exact Active jsonlog File Path β
PostgreSQL writes the current log paths into current_logfiles inside your data directory, or you can ask PostgreSQL directly via SQL:
sudo -u postgres psql -Atc "SELECT pg_current_logfile('jsonlog');"Combine that with SHOW data_directory; to get the full path (for example, /var/lib/postgresql/16/main/log/postgresql-2026-12-06.json).
Step 2: Stream PostgreSQL jsonlog Live into Logdy β
Install Logdy (single Go binary, no database or agent required):
brew install logdy
# or: curl https://logdy.dev/install.sh | shFollow the active PostgreSQL JSON log file:
# Follow new entries as PostgreSQL writes them
sudo logdy follow /var/lib/postgresql/16/main/log/postgresql-2026-12-06.json --port 8080
# Or load existing lines in the file first, then keep following
sudo logdy follow /var/lib/postgresql/16/main/log/postgresql-2026-12-06.json --full-read --port 8080Running PostgreSQL in Docker Compose instead? If your container logs to stdout or a mounted log directory, pipe directly into Logdy:
# Stream container logs directly into Logdy
docker compose logs -f postgres | logdy --port 8080
# Or follow a bind-mounted jsonlog file on the host
logdy follow ./pg-logs/postgresql-2026-12-06.json --full-read --port 8080Open http://127.0.0.1:8080 in your browser. If PostgreSQL is on a remote server, keep --ui-ip 127.0.0.1 (the default), optionally add --ui-pass "strong-password", and tunnel port 8080 over SSH:
ssh -L 8080:127.0.0.1:8080 [email protected]Key PostgreSQL jsonlog Fields to Turn into Logdy Facets β
Per PostgreSQL's official Table 19.5 (Keys and Values of JSON Log Entries), null string fields are omitted automatically. These fields are the most useful columns and sidebar facets in Logdy:
jsonlog Key | Type | What It Shows | Useful Filter in Logdy |
|---|---|---|---|
timestamp | string | Timestamp with milliseconds | Sort / inspect exact incident window |
error_severity | string | LOG, WARNING, ERROR, FATAL, PANIC | Facet to isolate ERROR / FATAL instantly |
dbname | string | Database name | Separate app DB from postgres maintenance queries |
user | string | Connected role/user name | Isolate migrations vs web app vs reporting jobs |
application_name | string | Client application_name | Filter by microservice or connection pool |
state_code | string | 5-character SQLSTATE code (e.g., 40P01 deadlock, 23505 unique violation) | Click-filter specific database error classes |
message | string | Primary log message (includes duration: 412.531 ms statement: ...) | Search duration: to isolate slow queries |
statement | string | Client-supplied SQL query string (on errors) | Inspect the exact failing SQL without line-wrapping breaks |
detail / hint | string | Extra error context and PostgreSQL hints | Expand row drawer to see constraint/parameter details |
pid / session_id | number / string | Backend process ID and session ID | Correlate every query from a single failing connection |
Example jsonlog Entry β
{
"timestamp": "2026-12-06 14:22:18.412 UTC",
"user": "app_web",
"dbname": "production",
"pid": 4812,
"remote_host": "10.0.2.15",
"remote_port": 51924,
"session_id": "69343b2a.12cc",
"line_num": 14,
"error_severity": "LOG",
"message": "duration: 842.190 ms statement: SELECT * FROM orders WHERE customer_id = $1 ORDER BY created_at DESC LIMIT 50",
"application_name": "checkout-api",
"backend_type": "client backend"
}Because jsonlog puts the entire multi-line SQL query into one JSON string instead of splitting it across indented lines, Logdy never breaks a single query into multiple fragmented log rows.
When to Use Logdy vs pgBadger vs pg_stat_statements β
| Tool | Primary Job | Real-Time Live Tail? | Historical Aggregate Reports? | Setup Effort |
|---|---|---|---|---|
| Logdy | Live interactive log browsing & incident triage | Yes (browser UI) | No | Single binary (logdy follow) |
pgBadger | Offline HTML report generator for Postgres logs | No (batch/incremental) | Yes (slowest queries, hourly graphs) | Perl script on rotated log files |
pg_stat_statements | In-database normalized query statistics | Queryable via SQL | Yes (cumulative calls, mean/total exec time) | Built-in PostgreSQL extension |
pgtail | Terminal TUI tailored for PostgreSQL logs | Yes (terminal) | No | CLI install |
Honest Limits of Using Logdy with PostgreSQL β
- No automatic SQL normalization or explain-plan aggregation: Logdy shows individual log events as they happen. Use
pg_stat_statementsto rank top queries by total CPU/time andauto_explain(withauto_explain.log_min_duration) if you want execution plans logged into the samejsonlogstream. - File rotation: When PostgreSQL rotates to a new daily filename (e.g.,
postgresql-2026-12-07.json), alogdy followprocess pointed at yesterday's filename will stop receiving new entries. Either use a fixedlog_filename = 'postgresql.log'withlog_truncate_on_rotation = on/ externallogrotate, or restartlogdy followagainst$(sudo -u postgres psql -Atc "SELECT pg_current_logfile('jsonlog');"). - In-memory buffer: Logdy retains the last
100,000messages in memory by default (--max-message-count). Settinglog_statement = 'all'on a busy production database will flood both disk and the ring bufferβstick tolog_min_duration_statementin production.
FAQ β
Which PostgreSQL version is required for jsonlog? β
PostgreSQL 15 or newer. PostgreSQL 15 introduced log_destination = 'jsonlog'. On PostgreSQL 14 or older, you can use csvlog or stderr and parse fields with a custom TypeScript middleware in Logdy.
Does log_min_duration_statement require restarting PostgreSQL? β
No. Changing log_min_duration_statement only requires reloading the configuration (SELECT pg_reload_conf(); or systemctl reload postgresql). Only enabling logging_collector = on requires a full server restart.
Why is pg_current_logfile('jsonlog') returning NULL? β
Either logging_collector is off, jsonlog is not included in log_destination, or PostgreSQL has not been restarted since logging_collector = on was added to postgresql.conf.
Can I view auto_explain plans inside Logdy? β
Yes. When auto_explain is loaded (shared_preload_libraries = 'auto_explain') and auto_explain.log_min_duration is set, PostgreSQL writes execution plans through the same logging collector into jsonlog, so they appear directly in Logdy's row detail drawer.
Is it safe to expose Logdy directly on a database server? β
Never bind Logdy to 0.0.0.0 on a public database server. Keep the default --ui-ip 127.0.0.1, set --ui-pass, and connect over an SSH tunnel (ssh -L 8080:127.0.0.1:8080 ...) or private VPN.
Related guides: Local JSON Log Viewer Β· Self-Hosted Papertrail & Better Stack Alternative Β· Remote Host Logs Browser UI
