PostgreSQL's Write-Ahead Logging (WAL) underpins everything from crash recovery to PITR and streaming replication. But streaming WALs safely and reliably, especially into cloud or container-native environments, can be fragile.
Enter pgrwl
: a modern WAL receiver written in Go that gives you:
- π WAL streaming to local/S3/SFTP
- π On-the-fly encryption + compression
- π³ Kubernetes-native workflows
- π Prometheus metrics + Grafana dashboards
- π§Ή Automatic retention + cleanup
- βοΈ Safe WAL handling, with proper
fsync
guarantees
Letβs explore how it works under the hood.
π§ͺ Note:
pgrwl
is a research project, inspired by PostgreSQLβs built-in tools likepg_receivewal
, and is
based on careful reading of their official source code and streaming behaviors.
pgrwl
serves as a starting point to explore more cloud-native, container-friendly, and extensible
implementations of these time-tested concepts.
π The Problem:
For a cloud-native WAL streamer, these features are expected:
- Cloud uploads (S3, SFTP)
- Streaming compression
- Encryption
- Metrics and observability
- Retention and cleanup
- Pod/container integration
Most of all, it should be integrated with modern DevOps pipelines.
βοΈ How pgrwl
Works
The architecture captures the streaming and archival lifecycle:
π Component Breakdown
π WAL Receiver
- Connects to PostgreSQL replication slot
- Receives
XLogData
messages viapglogrepl
- Buffers segment into a
.partial
file -
Once the 16 MiB boundary is reached:
-
fsync()
the file - Atomically rename to final segment
-
π§ Archive Supervisor
-
Periodically triggers:
- WAL uploader
- WAL retention sweeper
βοΈ WAL Uploader
- Scans for complete segments
- Compresses + encrypts
- Streams directly to remote storage
- Deletes local copy on success
π§Ή WAL Retainer
- Lists remote storage
- Applies time-based retention
- Deletes expired segments
π§ͺ Integrity Testing: Byte-for-Byte Fidelity
pgrwl
is tested to ensure:
- Received WALs match PostgreSQL originals
-
.partial
files are never uploaded - Segment naming and metadata are preserved
Related articles:
- Stream PostgreSQL WALs With Zero Data Loss In Mind
- Testing PostgreSQL WAL Streamers for Byte-Level Fidelity
π Use Cases
- π‘οΈ WAL archiving for disaster recovery (PITR)
- π Encrypted WAL pipelines
- π³ Kubernetes integration
π€ Contribute & Collaborate
You can help by:
- Suggest features
- File issues
- Improving CLI and UX
Start here: Contributing
π Links
- GitHub: hashmap-kz/pgrwl
- Docker:
ghcr.io/hashmap-kz/pgrwl
- Docs: In-repo README & examples
- License: MIT
Stream safely, backup smart. π
Top comments (0)