Skip to content

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-in log_destination option that serializes each server log entry as a single-line JSON object containing typed fields such as timestamp, error_severity, dbname, user, state_code, message, and statement.

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:

ini
# 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 = on

Tip: You can keep both plain-text and JSON logs during migration by setting log_destination = 'stderr, jsonlog'. PostgreSQL automatically appends .json to 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:

bash
# 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:

bash
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):

bash
brew install logdy
# or: curl https://logdy.dev/install.sh | sh

Follow the active PostgreSQL JSON log file:

bash
# 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 8080

Running PostgreSQL in Docker Compose instead? If your container logs to stdout or a mounted log directory, pipe directly into Logdy:

bash
# 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 8080

Open 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:

bash
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 KeyTypeWhat It ShowsUseful Filter in Logdy
timestampstringTimestamp with millisecondsSort / inspect exact incident window
error_severitystringLOG, WARNING, ERROR, FATAL, PANICFacet to isolate ERROR / FATAL instantly
dbnamestringDatabase nameSeparate app DB from postgres maintenance queries
userstringConnected role/user nameIsolate migrations vs web app vs reporting jobs
application_namestringClient application_nameFilter by microservice or connection pool
state_codestring5-character SQLSTATE code (e.g., 40P01 deadlock, 23505 unique violation)Click-filter specific database error classes
messagestringPrimary log message (includes duration: 412.531 ms statement: ...)Search duration: to isolate slow queries
statementstringClient-supplied SQL query string (on errors)Inspect the exact failing SQL without line-wrapping breaks
detail / hintstringExtra error context and PostgreSQL hintsExpand row drawer to see constraint/parameter details
pid / session_idnumber / stringBackend process ID and session IDCorrelate every query from a single failing connection

Example jsonlog Entry ​

json
{
  "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 ​

ToolPrimary JobReal-Time Live Tail?Historical Aggregate Reports?Setup Effort
LogdyLive interactive log browsing & incident triageYes (browser UI)NoSingle binary (logdy follow)
pgBadgerOffline HTML report generator for Postgres logsNo (batch/incremental)Yes (slowest queries, hourly graphs)Perl script on rotated log files
pg_stat_statementsIn-database normalized query statisticsQueryable via SQLYes (cumulative calls, mean/total exec time)Built-in PostgreSQL extension
pgtailTerminal TUI tailored for PostgreSQL logsYes (terminal)NoCLI 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_statements to rank top queries by total CPU/time and auto_explain (with auto_explain.log_min_duration) if you want execution plans logged into the same jsonlog stream.
  • File rotation: When PostgreSQL rotates to a new daily filename (e.g., postgresql-2026-12-07.json), a logdy follow process pointed at yesterday's filename will stop receiving new entries. Either use a fixed log_filename = 'postgresql.log' with log_truncate_on_rotation = on / external logrotate, or restart logdy follow against $(sudo -u postgres psql -Atc "SELECT pg_current_logfile('jsonlog');").
  • In-memory buffer: Logdy retains the last 100,000 messages in memory by default (--max-message-count). Setting log_statement = 'all' on a busy production database will flood both disk and the ring bufferβ€”stick to log_min_duration_statement in 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