Can your Postgres survive a bad query?
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.
Related posts
- What else runs on your Postgres server, and how do we stop it from taking the database down?
ClickHouse mediumAdept
Supporting processes on a managed Postgres VM (PgBouncer, WAL-G, Prometheus, exporters, log collector, watchdogs) share memory, CPU and disk with the database, so a leak or CPU burst in any of them can take it down. ClickHouse Managed Postgres confines them to a cgroup v2 slice using systemd MemoryHigh/MemoryMax, with per-service GOMEMLIMIT values summing below memory.high. Go's GC reacts first, the kernel throttles at memory.high, and any OOM at memory.max is scoped away from Postgres, which runs in a separate cgroup. Backups get reduced CPU weight, WAL-G buffers and log-collector memory are bounded, exported metrics are allowlisted, and a disk-full watchdog kills application sessions while exempting replication and monitoring roles.
- Benchmarking NVMe-backed Managed Postgres: PlanetScale and ClickHouse
ClickHouse mediumAdept
On identical AWS r8gd instances with local NVMe and quorum synchronous replication, ClickHouse Managed Postgres outperformed PlanetScale Metal in a pgbench TPC-B-like workload. Throughput was 34% higher at 4 vCPU and 51–54% higher at 16 vCPU on 100 GB and 500 GB datasets, with lower average latency. The gap is attributed to configuration rather than hardware: 2 MB huge pages (about 12% on their own), lz4 WAL compression, and max_wal_size sized to the instance (up to 256 GB) versus PlanetScale's 8 GB with huge pages and WAL compression disabled. The results come from a vendor benchmark, and the authors advise validating with your own workload.
- PostgresBench: A Reproducible Benchmark for Postgres Services
ClickHouse mediumAdept
PostgresBench is an open, reproducible benchmark for managed Postgres services built on pgbench's TPC-B-like workload (256 clients, 16 threads, 10-minute runs, three runs each) at ~100 GB and ~500 GB scale factors, with default configs, HA disabled and all services in us-east-2. In the first cohort, ClickHouse's NVMe-backed managed Postgres reached about 28.7K TPS on 16 vCPU/64 GB at 100 GB, versus 14.8K for Crunchy Bridge, 12.6K for Aurora, 8.6K for Neon and 8.1K for RDS, and held about 26K TPS at 500 GB. ClickHouse attributes the lead to co-located local NVMe storage, which avoids network round trips on every fsync and WAL commit in write-heavy workloads. Scripts and raw JSON results are on GitHub for verification and community submissions, though the vendor-run setup and absence of pricing comparisons are worth weighing.
- 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.
- Why strict memory overcommit matters for Postgres
ClickHouse mediumAdept
Under Linux's default overcommit policy, an OOM-killed Postgres backend forces the postmaster to terminate all backends and run crash recovery. Strict overcommit (vm.overcommit_memory=2) instead makes malloc return ENOMEM, so only the offending query fails. ClickHouse Managed Postgres sets an explicit vm.overcommit_kbytes of 80% of non-huge-page memory plus 2GB, roughly 60% of RAM plus 2GB, which leaves memory free to handle the error. On an m7i.2xlarge, the default policy dropped all 20 sessions with 30.2s of downtime, strict overcommit caused one query error and no dropped connections, and pgbench showed no measurable throughput cost.