Skip to main content

pg-perf-check

PyPI

Answer "why is this database slow?" with a scripted diagnostic report instead of guesswork. 24 threshold checks plus 7 read-only SQL files, each answering one question.

pip install pg-perf-check[psycopg]   # from PyPI, Python 3.9+
pg-perf-check --database-url "$DATABASE_URL"
pg-perf-check --list-checks
pg-perf-check --self-test            # no database needed

# or straight from a clone, no install:
pip install psycopg2-binary          # or: apt install python3-psycopg2
python3 run_diagnostics.py --database-url "$DATABASE_URL"
python3 run_diagnostics.py --list-checks
python3 run_diagnostics.py --self-test      # no database needed

Installing without the extra pulls no dependencies at all — the driver is optional and imported lazily, because the tool accepts either psycopg (v3) or psycopg2 and every no-database mode has to work on an interpreter with neither. The extras are [psycopg] and [psycopg2].

Connected to mydb on 127.0.0.1/5433 (PostgreSQL 17.11)
Running 24 checks and the sql/ files...

  connections              CONNECTIONS
    84 of 100 connection slots in use, 12 idle in transaction
    ...
    Suggested action:
      Put a connection pooler in transaction mode in front of PostgreSQL and cap
      the pool at roughly (2 x CPU cores) + effective_spindle_count. Do not raise
      max_connections as the first move: it multiplies memory use per backend.
    Source: sql/05-connections-and-locks.sql (Q5.0)

Everything here is read-only

No check writes, alters or drops anything, and none holds a lock beyond a normal SELECT. Each SQL file says so in its header so you can confirm before pointing it at production.

What it checks

24 threshold checks across connections, idle-in-transaction sessions, lock blocking chains, long-running queries, the oldest xmin horizon, replication slots pinning xmin, table and index bloat, unused and duplicate indexes, cache hit ratios, autovacuum health, and more — each with the evidence, the likely impact and a concrete action.

7 SQL files, each answering one question and safe to run alone:

File Question
01-table-sizes-and-bloat what is big, and what is dead weight?
02-unused-and-missing-indexes which indexes earn their keep, and what is missing?
03-slow-queries where is the time actually going?
04-index-usage scan counts, index sizes, redundancy
05-connections-and-locks who is waiting on whom?
06-cache-hit-and-io is it reading from cache or from disk?
07-vacuum-and-autovacuum is bloat accumulating, and why?

Verified against a real PostgreSQL 17.11

All 24 checks were executed against a live PostgreSQL 17.11 server, and the whole report was produced end to end from that server. Where pg_stat_statements is unavailable, the four extension-dependent checks are reported as skipped with the two-step install instructions, rather than failing or silently reporting nothing.

The 7 SQL files are executed by the runner too, which prints a per-file result line so you can see the state of your own server version. Exactly what that showed, and what was not verified:

  • 01, 02, 04, 05, 06 and 07 ran every statement cleanly on 17.11. 07-vacuum-and-autovacuum.sql reports 10/10 statements OK.
  • Two statements in 07-vacuum-and-autovacuum.sql did not, and are fixed: Q7.6 named pg_stat_progress_vacuum columns that PostgreSQL 17 replaced — max_dead_tuples / num_dead_tuples became max_dead_tuple_bytes, dead_tuple_bytes and num_dead_item_ids, a rename and a change of unit, so naming either set breaks the other branch. Q7.6 now reads those fields out of the row's JSON form (to_jsonb(p) ->> '…'), so it parses on every supported version and reports which branch you are on in a dead_store_units column. Q7.7 selected datname from pg_stat_user_tables, a column that has never existed on any release — that view is already scoped to the current database — and now selects schemaname / relname. Q7.6's 17+ branch was verified by catching a live throttled VACUUM (dead_store_units = bytes, dead_store_capacity = 67108864, i.e. the default 64 MiB maintenance_work_mem); Q7.7 was verified directly. Not verified: the pre-17 branch of Q7.6, because no PostgreSQL 16-or-older server was available.
  • Two check-output defects were found during that same verification and are also fixed: shared_buffers_low reported approximately 0 MB for a stock 128 MB shared_buffers because the parser ignored pg_settings.unit (setting = 16384, unit = 8kB) — it now prints approximately 128 MB — and autovacuum_throttled printed vacuum_cost_page_miss = None, vacuum_cost_page_dirty = None because the settings query selected neither; it now prints 2 and 20.
  • 03-slow-queries.sql needs the pg_stat_statements extension. On a server without it, seven of its eight statements fail with relation "pg_stat_statements" does not exist, and the runner reports exactly that alongside the install instructions. That is a missing extension on the server, not a broken statement, and it is the only remaining failure the runner prints on a stock 17.11 server without that extension.

The advice it gives about its own output

Worth quoting, because it is the part most tooling gets wrong:

Change ONE thing, then re-run this script and compare. Two changes at once means you cannot tell which one helped. […] Changing a setting is not the same as fixing a query.

Counters are cumulative since the last statistics reset, so the counter-based findings (unused indexes, sequential scans, cache ratios) only mean something after a full business cycle.

What it is not

It diagnoses; it does not tune for you. It cannot know your workload, so it cannot tell you whether a missing index is worth the write cost. EXPLAIN-GUIDE.md covers reading plans; designing an index is your call.

Results also depend on your statistics being current — on a server where ANALYZE has not run recently, estimated row counts will mislead you.

Requirements

Python 3.9+ (the package declares >=3.9; the code itself runs on 3.8), PostgreSQL 12+, and a Postgres driver — psycopg (v3) or psycopg2, either one, installed explicitly or via pip install pg-perf-check[psycopg]. With no driver and no database, --help, --list-checks and --self-test still work; a connection attempt without a driver exits 2 with the install command to run.

The full pack

The paid kit adds the two playbooks this repository does not ship — INDEXING-PLAYBOOK.md (how to design an index the planner actually uses, with page counts and WAL volumes measured on a live PostgreSQL 17.11 server rather than asserted) and REMEDIATION-PLAYBOOK.md (one section per check: the threshold that fired, what the counter really counts, the false positives to rule out, the SQL with the guards that stop it being an outage, and how to verify the fix worked) — plus the CI harness that turns the --json report into a baseline comparison, failing a build only on findings that are new or worse.

  • pg-restore-drill — Prove your PostgreSQL backup actually restores: a scripted point-in-time recovery drill with a measured RPO/RTO report and a negative control. (if you were searching for "test postgres backup restore")
  • postgres-migration-safety-lint — Lint SQL migrations before they run: finds statements that take an ACCESS EXCLUSIVE lock, rewrite a table, or destroy data, and gives the safe rewrite. (if you were searching for "postgres migration lock")
  • rls-policy-tester — Prove user A cannot read user B's rows in Postgres or Supabase with row level security, including negative controls that fail on a missing policy. (if you were searching for "supabase rls test")

All 28 tools in this set, grouped by what they check: dev-tools-index

If you arrived here searching for one of these, this is the tool: postgres performance tuning queries · find missing indexes postgres · table bloat check postgresql · why is my postgres query slow

→ Postgres Performance Toolkit — $29 on Gumroad

Metadata

Release files for pg-perf-check 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pg-perf-check 0.1.0
File Size Uploaded Provenance Actions
pg_perf_check-0.1.0.tar.gz 86.8 kB Without provenance Details for pg_perf_check-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pg-perf-check 0.1.0
File Interpreter ABI Platform Actions
pg_perf_check-0.1.0-py3-none-any.whl Python 3 none any Details for pg_perf_check-0.1.0-py3-none-any.whl

Total release size: 173.1 kB

Release files / pg_perf_check-0.1.0.tar.gz

Download URL pg_perf_check-0.1.0.tar.gz
Size 86.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4f23fcdb46fdfc2f920ce362b6571427cc7b382668287fe4a4955a72d8c2496c
BLAKE2b-256 checksum
How to use checksums
af0c511138188a6293657bc34f4683a5642ade3ccbaa8b3f2131089b8ca0562c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / pg_perf_check-0.1.0-py3-none-any.whl

Download URL pg_perf_check-0.1.0-py3-none-any.whl
Size 86.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d15622de52e5d4006fc00085bf50737d9838296f713956aef6200ae43d34848
BLAKE2b-256 checksum
How to use checksums
3fdd721a481a33b74abeeb2f8bd8db2260be0bdb2746beecb579b826df67f3f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for pg-perf-check 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page