← All compilation units

Flyology.Postgres.Replication.Server_Sessions

Description

Backend response sequences for PostgreSQL replication-mode commands and COPY BOTH streaming.

Begin_Streaming

procedure Begin_Streaming
  (Client : in out Sessions.Session; Timeout : Duration)

Enter COPY BOTH mode for a successful START_REPLICATION command.

Parameters
Client

Authenticated replication session to write.

Timeout

Maximum time allowed for the response write.

Complete_Streaming

procedure Complete_Streaming
  (Client : in out Sessions.Session; Timeout : Duration)

Complete START_REPLICATION after both COPY BOTH directions close. A frontend CopyFail should instead be answered with an error response.

Parameters
Client

Session whose COPY directions have both closed.

Timeout

Per-message completion write timeout.

Finish_Streaming

procedure Finish_Streaming
  (Client : in out Sessions.Session; Timeout : Duration)

Close the server-to-standby direction. The caller must also observe frontend CopyDone before Complete_Streaming, either beforehand via Read_Standby_Message or afterward while reading frontend COPY messages.

Parameters
Client

Streaming replication session to finish.

Timeout

Maximum time allowed to send CopyDone.

Read_Standby_Message

function Read_Standby_Message
  (Client : in out Sessions.Session; Timeout : Duration)
   return Stream_Message

Read and decode one standby CopyData message, or signal CopyDone.

Parameters
Client

Streaming replication session to read.

Timeout

Maximum time allowed for the complete message.

Return value

Standby status update or hot-standby feedback.

Raised exceptions
Standby_Copy_Done

The standby closed its send direction.

Protocol_Error

The COPY command or CopyData is malformed, or the standby sent CopyFail.

Send_Create_Logical_Slot

procedure Send_Create_Logical_Slot
  (Client           : in out Sessions.Session;
   Slot_Name        : String;
   Consistent_Point : LSN;
   Plugin           : String;
   Snapshot_Name    : String := "";
   Timeout          : Duration)

Send the four-column CREATE_REPLICATION_SLOT result and ReadyForQuery. Snapshot_Name is SQL NULL when empty, as required for SNAPSHOT 'use' and SNAPSHOT 'nothing'.

Parameters
Client

Authenticated replication session to write.

Slot_Name

Name assigned to the created slot.

Consistent_Point

LSN from which decoding can start.

Plugin

Logical decoding output plugin.

Snapshot_Name

Exported snapshot, or empty for SQL NULL.

Timeout

Per-message write timeout.

Send_Drop_Replication_Slot

procedure Send_Drop_Replication_Slot
  (Client : in out Sessions.Session; Timeout : Duration)

Send DROP_REPLICATION_SLOT completion and ReadyForQuery.

Parameters
Client

Authenticated replication session to write.

Timeout

Per-message write timeout.

Send_Identify_System

procedure Send_Identify_System
  (Client         : in out Sessions.Session;
   System_Id      : UInt64;
   Timeline       : UInt32;
   Current_WAL    : LSN;
   Database       : String := "";
   Timeout        : Duration)

Complete IDENTIFY_SYSTEM as a four-column simple-query response. An empty Database is encoded as SQL NULL for a physical connection.

Parameters
Client

Authenticated replication session to write.

System_Id

Stable system identifier rendered as decimal text.

Timeline

Current timeline identifier.

Current_WAL

Current end-of-WAL position.

Database

Connected database name, or empty for SQL NULL.

Timeout

Per-message write timeout.

Send_Primary_Keepalive

procedure Send_Primary_Keepalive
  (Client          : in out Sessions.Session;
   WAL_End         : LSN;
   Sent_At         : Replication_Timestamp;
   Reply_Requested : Boolean := False;
   Timeout         : Duration)

Send a primary keepalive frame inside COPY BOTH.

Parameters
Client

Streaming replication session to write.

WAL_End

Server's current end-of-WAL position.

Sent_At

PostgreSQL replication timestamp for the frame.

Reply_Requested

Ask the standby for immediate status feedback.

Timeout

Maximum time allowed for the write.

Send_Show

procedure Send_Show
  (Client    : in out Sessions.Session;
   Parameter : String;
   Value     : String;
   Timeout   : Duration)

Complete replication SHOW as a one-column simple-query response.

Parameters
Client

Authenticated replication session to write.

Parameter

Parameter name used as the result-column label.

Value

Parameter value encoded as text.

Timeout

Per-message write timeout.

Send_Timeline_History

procedure Send_Timeline_History
  (Client   : in out Sessions.Session;
   Timeline : UInt32;
   Contents : Byte_Array;
   Timeout  : Duration)

Complete TIMELINE_HISTORY with the filename and exact history bytes. PostgreSQL declares both columns as text; walreceivers persist Contents verbatim.

Parameters
Client

Authenticated replication session to write.

Timeline

Timeline whose history filename is returned.

Contents

Raw history-file contents.

Timeout

Per-message write timeout.

Send_XLog_Data

procedure Send_XLog_Data
  (Client    : in out Sessions.Session;
   WAL_Start : LSN;
   WAL_End   : LSN;
   Sent_At   : Replication_Timestamp;
   Data      : Byte_Array;
   Timeout   : Duration)

Send one XLogData frame inside COPY BOTH.

Parameters
Client

Streaming replication session to write.

WAL_Start

LSN of the first byte represented by Data.

WAL_End

Server's current end-of-WAL position.

Sent_At

PostgreSQL replication timestamp for the frame.

Data

Raw WAL or logical-decoding payload.

Timeout

Maximum time allowed for the write.

Standby_Copy_Done

Standby_Copy_Done : exception;

The standby closed its send direction with a valid CopyDone frame.