The Postgres mistakes we all still make
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.
Related posts
- Postgres Support Recap: Investigating Postgres Query Performance
Neon mediumAdept
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.
- Incident Report: December 8th, 2025
Railway mediumAdeptA schema migration adding a nullable column to a ~1 billion row PostgreSQL table stalled behind locks held by a long-running query. Waiting connections piled up until PgBouncer exceeded the database connection limit, so backend replicas failed health checks and dropped out of rotation, taking down the dashboard, CLI, login, GitHub deploys and API for about eight minutes. Running deployments stayed up. Railway plans to raise database connection limits, reconfigure PgBouncer to fit within them, and fix the long-running query.
- PostgreSQL Stories: A simple query with a big problem
Render mediumAdept
A seemingly simple indexed join with LIMIT 1 ran for over four hours on Render's staging PostgreSQL, holding a lock that blocked CREATE OR REPLACE VIEW migrations and stalled deploys. The team traced it by watching oldest-transaction age, querying pg_stat_activity for long-running active queries, and using pg_blocking_pids() to map which backends blocked which migrations. The culprit was an engineer's ad-hoc psql query: pressing Ctrl+C in psql stopped reading results but left the server-side query running. Killing the backend fixed it immediately. Key lessons are to keep transactions short, because they block locks, autovacuum and risk XID wraparound, and to set application_name and inspect usename so queries can be traced to their source.
- Using Neon’s Scale to Zero with Long-Running Applications
Neon mediumAdept
Neon's scale to zero suspends a Postgres compute after an idle window (only when no WAL senders are active and autovacuum isn't running), which severs connections held by long-running servers. A naive node-postgres Client crashes on the resulting unhandled error event. A client-side pg.Pool with an error handler tolerates the dropped connections and reconnects on demand, waking the database. In Apache Bench tests the pool beat per-request connections by more than 10x (about 46ms vs 678ms average latency, 370 vs 26 req/s), with the same pattern shown in a Fastify, Drizzle and HTMX example app.
- Can your Postgres survive a bad query?
ClickHouse hardMaster
Postgres's `work_mem` limits memory per plan node per process, not per query, so parallel workers and `hash_mem_multiplier` can push a simple aggregation past 8x `work_mem`. Some structures never spill: the deduplication hashtable behind `WITH RECURSIVE ... UNION` stays in memory for the whole query and can grow unbounded. A benchmark ran 7-23 concurrent copies of such a query (~1 GiB each) against ClickHouse Managed Postgres, Cloud SQL, PlanetScale and RDS. With overcommit disabled, ClickHouse returned clean SQLSTATE 53200 errors and kept the cluster up in every run, while RDS hit the OOM killer and crash recovery from 19 connections and the supervisor-based providers terminated sessions or crashed under load.