Skip to main content

Module postgres_io

Module postgres_io 

Source
Expand description

PostgreSQL logical replication I/O functions.

Provides low-level functions for connecting to PostgreSQL, managing replication slots, and parsing/encoding replication wire messages.

§Architecture

  • Control-plane connection (connect, ensure_replication_slot): Feature-gated behind postgres-cdc, uses tokio-postgres for slot management and metadata queries.
  • Replication streaming: WAL streaming uses pgwire-replication which implements the CopyBoth sub-protocol natively. See build_replication_config() for config conversion.
  • Wire format (parse_replication_message, encode_standby_status, build_start_replication_query): Always available, retained as test utilities and protocol documentation.

§Wire Format

Replication messages inside CopyData frames:

  • XLogData (tag w): 25-byte header + WAL payload
  • PrimaryKeepalive (tag k): 18 bytes with WAL position and reply flag
  • StandbyStatusUpdate (tag r): 34 bytes sent from client to server

Enums§

ReplicationMessage
A message received from the PostgreSQL replication stream.

Functions§

build_replication_config
Builds a [pgwire_replication::ReplicationConfig] from a PostgresCdcConfig.
build_start_replication_query
Builds the START_REPLICATION SQL command.
connect
Connects to PostgreSQL as a regular (control-plane) connection.
drop_replication_slot
Drop a PostgreSQL logical replication slot.
encode_standby_status
Encodes a standby status update message.
ensure_replication_slot
Ensures the replication slot exists, creating it if necessary.
parse_replication_message
Parses a raw replication message from byte data.