Postgres Support Recap: Investigating Postgres Query Performance
Three starting points for diagnosing slow Postgres queries: use pg_stat_statements to find long-running queries by mean execution time and then EXPLAIN ANALYZE them, check the cache hit ratio (in Neon via the neon_stat_file_cache view, since Neon extends shared buffers with a local file cache), and look for table and index bloat caused by MVCC dead tuples. A hit ratio below 99% suggests the working set doesn't fit in memory, which calls for more shared_buffers or a larger Neon compute. Bloat is reduced with VACUUM, VACUUM FULL or REINDEX, all of which take locks. PgHero, run via Docker, gives a free dashboard alternative.
Related posts
- Performance tips for Neon Postgres
Neon mediumAdept
Neon's serverless Postgres follows mostly standard Postgres tuning, plus a few Neon-specific checks. Size compute at roughly 100 connections per GB of RAM, use pooling and autoscaling, then find slow queries with pg_stat_statements and EXPLAIN (ANALYZE, BUFFERS). Fix them with indexes, REINDEX and autovacuum tuning against bloat, and by keeping the local file cache hit ratio (shown in neon_stat_file_cache) above 99%. For faster ingests, batch inserts, drop unused indexes, offload reads to ephemeral read replicas, and test changes safely on a database branch.
- Debug your Postgres from the terminal: a tour of `neon inspect db`
Neon mediumAdept
`neon inspect db` adds fourteen read-only Postgres diagnostic subcommands to the Neon CLI, each running one curated query against Postgres statistics and catalog views (table/index sizes, bloat, unused indexes, seq scans, long-running queries, locks, pg_stat_statements outliers and calls, vacuum stats, replication slots, subscriptions). Connections resolve automatically for linked Neon projects, and most commands also work on any Postgres via `--db-url`. Output is bounded and available as JSON or YAML, which makes it safer for agents than raw SQL access. Neon-specific commands report Local File Cache hit rate (aim for 0.99+) and working set versus LFC size to signal when to scale compute, since Neon pins shared_buffers at 128 MB.
- Introducing Postgres Query Insights in ClickHouse Cloud
ClickHouse mediumAdept
Postgres Query Insights, now in preview for ClickHouse Cloud Managed Postgres, ranks every normalized query pattern by impact and aggregates per-execution counters (CPU, cache vs disk reads, temp spills, unlaunched parallel workers, WAL) to explain why a pattern is slow. A worked example traces a p99 regression to a sort spilling to disk, confirmed with EXPLAIN (ANALYZE, BUFFERS) and fixed with an index or work_mem tuning. Telemetry comes from pg_stat_ch, an Apache 2.0 extension that normalizes literals at parse-analyze time so values and PII never leave the database. It enqueues raw per-statement events via a non-blocking try-lock on a shared-memory ring buffer at about 3% overhead, dropping events under pressure rather than back-pressuring Postgres.
- The Postgres mistakes we all still make
Neon mediumAdept
Five common Postgres mistakes all eventually show up as connection pressure: opening a connection per request, appending to JSONB columns, holding transactions open across external API calls, nightly bulk DELETEs, and unused indexes. Each comes with a detection query and a fix. In a pgbench test, per-transaction connects hit 1,415 TPS, PgBouncer 31,524, and persistent connections 215,538. The fixes are to pool connections, move accumulating facts into tables to avoid MVCC bloat, keep only SQL inside transactions using idempotency keys plus idle/transaction timeouts, partition and drop instead of DELETE, and drop unused indexes that slow writes and disable HOT updates.
- Monitor These Key Neon Metrics Via Datadog
Neon mediumAdept
Neon now exports database metrics to Datadog via an API-key integration covering all computes in a project. The metrics include connection counts, replication lag, CPU and memory, Local File Cache hits and misses, an estimated working set size, and pg_stat_database aggregates. A low LFC hit ratio or high miss count usually means the working set exceeds cache memory and reads are falling through to pageserver getpage requests, so the fix is a larger compute or better queries and indexes. Watching working set size trends, deadlocks and row operations helps with autoscaling limits and spotting inefficient queries, and an importable JSON dashboard is provided.