postgresql-replicant-0.2.0.1: PostgreSQL logical streaming replication library
Copyright(c) James King 2020 2021
LicenseBSD3
Maintainerjames@agentultra.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Replicant.Protocol

Description

This module implements the Postgres streaming replication protocol.

See: https://www.postgresql.org/docs/9.5/protocol-replication.html

Synopsis

Documentation

data IdentifySystem Source #

The information returned by the IDENTIFY_SYSTEM command establishes the stream's log start, position, and information about the database.

identifySystemSync :: ReplicantConnection -> IO (Maybe IdentifySystem) Source #

Synchronously execute the IDENTIFY SYSTEM command which returns some basic system information about the server.

startReplicationCommand :: ReplicantConnection -> ByteString -> LSN -> IO ByteString Source #

Create a START_REPLICATION_SLOT query, escaping the slot name passed in by the user.

handleCopyOutData :: TChan PrimaryKeepAlive -> WalProgressState -> ReplicantConnection -> (Change -> IO LSN) -> IO () Source #

This handles the COPY OUT mode messages. PostgreSQL uses this mode to copy the data from a WAL log file to the socket in the streaming replication protocol.

handleReplicationError :: ReplicantConnection -> IO () Source #

Used to re-throw an exception received from the server.

startReplicationStream :: ReplicantConnection -> ByteString -> LSN -> Int -> (Change -> IO LSN) -> IO () Source #

Initiate the streaming replication protocol handler. This will race the keep-alive and copy data handler threads. It will catch and rethrow exceptions from either thread if any fails or returns.

keepAliveHandler :: ReplicantConnection -> TChan PrimaryKeepAlive -> WalProgressState -> IO () Source #

This listens on the channel for primary keep-alive messages from the server and responds to them with the update status message using the current WAL stream state. It will attempt to buffer prior update messages when the socket is blocked.