LogBook


2025/07/13 [Learn Postgres]

Physical replication relies on the concept of streaming WAL segments from primary node to a replica node. The replica is in the state of continuous recovery – it continuously execute WAL segments received from primary node.
In Synchronous replication primary node ensures replica received WAL segments before completion, while in asynchronous mode WAL segments are streamed to the replica without waiting for return code.
Primary node has to store more WAL segments when replication is enabled in case the replica node is temporarily down. When replica is back up, primary node need to send all “missed” WAL segments, otherwise replica won’t be able to recover. Amount of “extra” WAL segments stored by primary node can be defined with wal_keep_segments setting. Since a single WAL segment has 16MB, setting wal_keep_segments to 100 will mean that primary server stores 1.6GB of extra WAL segments at any given time. This problem can be mitigated by the feature called slots, which ensure that WAL segments sent to replica are being removed from the primary node . You can create and remove a slot using pg_create_physical_replication_slot('master') and pg_drop_replication_slot('master') commands.