Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 4 min read Case study mediumAdept

Why we rewrote WAL-G for Postgres backups in Rust: Meet WAL-RUS

WAL-RUS is an open-source Rust rewrite of WAL-G's Postgres backup and WAL archival tooling, built because Go's garbage-collected runtime made virtual memory hard to predict in resource-constrained managed Postgres environments where overcommit is disabled. It uses bounded worker pools, a persistent daemon with long-lived object storage connections, and a low-copy streaming read-compress-upload pipeline, while keeping WAL-G's WALG_ config variables and two-way archive compatibility. In a WAL-heavy benchmark with four workers archiving to S3, WAL-RUS peaked below 1 GB of virtual memory versus nearly 2.8 GB for WAL-G (over 70% less), with comparable throughput and CPU. pgBackRest also had tight memory but built a larger backlog under heavy WAL activity. WAL-RUS adds incremental backups based on Postgres 17 WAL summaries and is slated to become the default for ClickHouse Cloud's managed Postgres.

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.

  • What is WAL backpressure, and why does ClickHouse Managed Postgres need it?

    ClickHouse hardMaster

    ClickHouse Managed Postgres prevents WAL-full PANICs, which happen when writes outpace archiving to object storage, by throttling client write bandwidth with the cgroup v2 I/O controller. A systemd timer counts pending WAL segments every 15 seconds and applies tiered write caps of 80%, 50% and 20% of provisioned disk throughput at 100, 500 and 1,000 segments. Processes are sorted by process title into an immune cgroup (archiver, checkpointer, WAL writer, logger) and a throttled one (client backends), and reads are never capped. In a pgbench test with a rate-limited archive_command, the backlog peaked at 3,433 segments (53 GiB), the disk never passed 33% full, and the backlog drained in under four minutes once storage recovered. One caveat: WAL-heavy workloads see throughput cut much more than WAL production, which fell only about 10%.

  • 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.

  • Postgres WASM by Snaplet and Supabase

    Supabase mediumAdept

    postgres-wasm runs a full PostgreSQL 14 server in the browser by emulating an x86 machine with v86 rather than compiling Postgres to WASM directly. It boots a minimal Buildroot Linux image and lazily loads the rest over a 9P filesystem via HTTPS, and it uses the page_poison=on kernel parameter so freed memory compresses well, which brings the snapshot of a running Postgres down to about 12MB. Networking goes through a forked websockproxy that converts raw ethernet frames into TCP, with an nginx reverse proxy that maps private IPs to ports so external clients like psql, PgAdmin or a logical replication peer can connect. Other hurdles included a v86 JIT bug that caused PG14 segfaults, worked around by switching Postgres to sysv shared memory, and an inbox-folder listener for running scripts inside the VM.

  • Architecture decisions in Neon

    Neon mediumAdept

    Neon built serverless Postgres by separating storage from compute without forking Postgres. Postgres streams WAL over the network to a separate WAL service of safekeeper nodes, which use consensus for durability and to prevent split-brain. Multi-tenant pageservers rebuild any page version on request. All historical page versions are kept in immutable, LSM-inspired files that are compressed and offloaded to object storage like S3, which replaces traditional backups and WAL archives and makes point-in-time recovery and branching cheap.

The quest for software engineering knowledge.

Look:
Layout: