46.6. Streaming Replication Protocol

To initiate streaming replication, the frontend sends the "replication" parameter in the startup message. This tells the backend to go into walsender mode, where a small set of replication commands can be issued instead of SQL statements. Only the simple query protocol can be used in walsender mode. The commands accepted in walsender mode are:

IDENTIFY_SYSTEM

Requests the server to identify itself. Server replies with a result set of a single row, and two fields: systemid: The unique system identifier identifying the cluster. This can be used to check that the base backup used to initialize the slave came from the same cluster. timeline: Current TimelineID. Also used to check that the slave is consistent with the master.

START_REPLICATION XXX/XXX

Instructs backend to start streaming WAL, starting at point XXX/XXX. Server can reply with an error e.g if the requested piece of WAL has already been recycled. On success, server responds with a CopyOutResponse message, and backend starts to stream WAL as CopyData messages. The payload in CopyData message consists of the following format.

XLogData (B)

Byte1('w')

Identifies the message as WAL data.

Int32

The log file number of the LSN, indicating the starting point of the WAL in the message.

Int32

The byte offset of the LSN, indicating the starting point of the WAL in the message.

Byten

Data that forms part of WAL data stream.

A single WAL record is never split across two CopyData messages. When a WAL record crosses a WAL page boundary, however, and is therefore already split using continuation records, it can be split at the page boundary. In other words, the first main WAL record and its continuation records can be split across different CopyData messages.