Evidence collection

Read the collector before you run it.

The investigation starts from a read-only psql script that your team runs and reviews. No credentials leave your environment, and nothing is installed.

How to run it

psql "host=... dbname=... user=..." -X -f pg-evidence-collector.sql -o evidence.txt
  • Connect to the application database as a role with pg_monitor. On RDS or Aurora, the master user can grant it to a dedicated role: GRANT pg_monitor TO your_role;
  • The script sets default_transaction_read_only = on, a 30-second statement_timeout and a 1-second lock_timeout for its own session.
  • Supports PostgreSQL 13 and later. Tested against PostgreSQL 14 and 17 with a pg_monitor role. Not yet tested against RDS or Aurora themselves.
  • Run it once during a normal period and, if you can, once while the problem is happening.

What it collects

SectionSourceWhy
Server and settingsversion(), pg_settings (non-default only), extensionsContext for every other number
Database activitypg_stat_databaseCache hit ratio, temp files, rollbacks, deadlocks
Top statementspg_stat_statements, top 50 by total timeWhere database time actually goes
Tables and indexespg_stat_user_tables, pg_stat_user_indexesSize, scan patterns, dead tuples, vacuum and analyze timing, unused indexes
Connections and waitspg_stat_activity, pg_blocking_pids()Pool behaviour, idle transactions, current blocking
Maintenance healthTransaction ID age, checkpoints, replication slots, vacuum progressProblems that build up slowly before they hurt

What it does not collect

  • No table data. It reads only statistics and catalog views.
  • No passwords or connection strings.
  • No literal values from pg_stat_statements. PostgreSQL normalizes them to $1, $2, ….

Review before you send

The output is a plain text file. Read it first. Table, column and index names appear throughout, and the current-activity section includes the first 120 characters of running queries, which can contain literal values. Delete or redact anything you are not comfortable sharing; the investigation notes what was removed.

What else helps

  • Representative EXPLAIN (ANALYZE, BUFFERS) output for the slow requests, from a safe environment.
  • A short timeline: when the symptom started, plus deploys, migrations and configuration changes around it.
  • On RDS or Aurora: Database Insights and CloudWatch exports for the same window. See what each source answers.
Production evidence

Need an independent PostgreSQL investigation?

Start with the problem and the evidence you already have. You will get a direct answer on whether a scoped investigation is the right next step.

Prefer to talk first? Book a 20-minute triage call.