When people talk about database replication they often imagine entire tables being copied from one server to another. It sounds heavy slow and fragile. PostgreSQL chose a very different path. Instead of copying data it copies memory. That memory is the Write Ahead Log or WAL and the two processes that move this memory across machines are the WAL sender and the WAL receiver. Together they form the invisible nervous system that keeps a primary database and its standbys in perfect alignment.

Everything begins on the primary server where all writes happen. When a client inserts or updates data PostgreSQL does not immediately rush to update files on disk. It first writes a record of that change into WAL. This record is a precise description of what changed not the data itself but the actions that produced it. These WAL records are appended in strict order forming a timeline of the database’s life.

The $WAL sender is a background process that watches this timeline. As soon as new WAL records are written it reads them and streams them over the network to any connected standbys. It does not wait for checkpoints or table writes. It sends the database’s memory as it is being formed. This makes replication fast and continuous rather than periodic and bulky.

On the other side sits the WAL receiver on the standby server. Its job is to accept this stream and write it into the standby’s own WAL files. At this stage the standby has not yet applied the changes to its tables. It is simply building up the same memory the primary has. The standby is listening to the primary’s thoughts before they become physical reality on disk.

Another background process on the standby then reads these WAL files and replays them. It applies each change to the standby’s data pages in exactly the same order they happened on the primary. Insert this row. Update that value. Delete that record. By following the same log the standby reconstructs the same database state without ever being told what the state is. It learns by replaying history.

This design has deep consequences. Because the standby is driven by WAL it does not need special replication logic for every table or index. All data types all schemas and all operations are handled by the same universal mechanism. If it happened on the primary and it was logged it will happen on the standby.

It also means the standby can always catch up. If the network drops the WAL receiver simply reconnects and asks the sender for the WAL it missed. Because WAL is stored on disk on the primary the history is still there. Replication is resilient to interruptions because it is based on a durable log not on fragile snapshots.

The result is a system that feels almost alive. The primary thinks and the standbys listen. The sender speaks and the receiver remembers. Together they keep multiple machines sharing a single consistent reality even though they may be thousands of miles apart.

This is why PostgreSQL replication is so reliable. It is not copying data. It is sharing memory.

@Walrus 🦭/acc #walrus