postgleam/replication

Types

Log Sequence Number - PostgreSQL’s position in the WAL

pub type Lsn {
  Lsn(value: Int)
}

Constructors

  • Lsn(value: Int)

A WAL data message from PostgreSQL

pub type WalMessage {
  XLogData(
    wal_start: Int,
    wal_end: Int,
    server_time: Int,
    data: BitArray,
  )
  PrimaryKeepalive(
    wal_end: Int,
    server_time: Int,
    reply_requested: Bool,
  )
}

Constructors

  • XLogData(
      wal_start: Int,
      wal_end: Int,
      server_time: Int,
      data: BitArray,
    )

    XLogData: WAL start, WAL end, server timestamp, and data payload

  • PrimaryKeepalive(
      wal_end: Int,
      server_time: Int,
      reply_requested: Bool,
    )

    Primary keepalive: WAL end, server timestamp, reply requested flag

Values

pub fn connect(
  config cfg: config.Config,
) -> Result(connection.ConnectionState, error.Error)

Start a replication connection by connecting with the replication parameter

pub fn decode_lsn(lsn: String) -> Result(Int, Nil)

Decode an LSN string to its integer representation

pub fn disconnect(state: connection.ConnectionState) -> Nil

Disconnect a replication connection

pub fn encode_lsn(lsn: Int) -> Result(String, Nil)

Encode an LSN integer to its string representation (e.g., “1/F73E0220”)

pub fn query(
  state: connection.ConnectionState,
  sql: String,
  timeout: Int,
) -> Result(
  #(
    List(connection.SimpleQueryResult),
    connection.ConnectionState,
  ),
  error.Error,
)

Execute a simple query on a replication connection. Used for CREATE_REPLICATION_SLOT etc.

pub fn receive_wal_message(
  state: connection.ConnectionState,
  timeout: Int,
) -> Result(
  #(Result(WalMessage, Nil), connection.ConnectionState),
  error.Error,
)

Receive the next WAL message from a streaming replication connection. Returns either a parsed WAL message or an indication that streaming has ended.

pub fn send_standby_status(
  state: connection.ConnectionState,
  written: Int,
  flushed: Int,
  applied: Int,
  timestamp: Int,
  reply_requested: Bool,
) -> Result(connection.ConnectionState, error.Error)

Send a standby status update to the server. All LSN values are 64-bit unsigned integers (microseconds since 2000-01-01).

pub fn start_streaming(
  state: connection.ConnectionState,
  sql: String,
  timeout: Int,
) -> Result(connection.ConnectionState, error.Error)

Start streaming replication. Sends the START_REPLICATION command and waits for CopyBothResponse.

pub fn stop_streaming(
  state: connection.ConnectionState,
  timeout: Int,
) -> Result(connection.ConnectionState, error.Error)

Stop streaming by sending CopyDone, then receive CommandComplete + ReadyForQuery

Search Document