Skip to main content

Crate pgwire_replication

Crate pgwire_replication 

Source
Expand description

§pgwire-replication

A Tokio-based PostgreSQL logical replication client implementing the pgoutput protocol.

§Features

  • Async/await - Built on Tokio for high-performance async I/O
  • TLS support - Optional rustls-based encryption with verify modes
  • SCRAM-SHA-256 - Secure password authentication
  • pgoutput protocol - Native logical replication decoding

§Quick Start

use pgwire_replication::{ReplicationClient, ReplicationConfig, ReplicationEvent, Lsn};

let config = ReplicationConfig::new(
    "localhost",
    "postgres",
    "secret",
    "mydb",
    "my_slot",
    "my_publication",
)
.with_start_lsn(Lsn::ZERO);

let mut client = ReplicationClient::connect(config).await?;

while let Some(ev) = client.recv().await? {
    match ev {
        ReplicationEvent::XLogData { wal_end, data, .. } => {
            println!("Got data at {}: {} bytes", wal_end, data.len());
        }
        ReplicationEvent::KeepAlive { wal_end, .. } => {
            println!("Keepalive at {}", wal_end);
        }
        ReplicationEvent::Message { prefix, content, .. } => println!(
            "Logical message: prefix={}, {} bytes", prefix, content.len()
        ),
        ReplicationEvent::StoppedAt {reached: _} => break,
        ReplicationEvent::Begin { .. } => println!(
            "Transaction start, probably want to flush in-flight events to the sinks."
        ),
        ReplicationEvent::Commit { .. } => println!(
            "Transanction finished, good time to store a checkpoint at the higher level."
        ),
    }
}

§Feature Flags

  • tls-rustls (default) - TLS support via rustls
  • scram (default) - SCRAM-SHA-256 authentication
  • md5 - MD5 authentication (legacy)

Re-exports§

pub use client::ReplicationClient;
pub use client::ReplicationEvent;
pub use client::ReplicationEventReceiver;
pub use client::ReplicationMetrics;
pub use config::Publication;
pub use config::ReplicationConfig;
pub use config::SslMode;
pub use config::TlsConfig;
pub use error::PgWireError;
pub use error::Result;
pub use lsn::Lsn;

Modules§

auth
Authentication mechanisms for PostgreSQL connections.
client
PostgreSQL logical replication client.
config
Configuration types for PostgreSQL replication connections.
error
Error types for pgwire-replication.
lsn
PostgreSQL Log Sequence Number (LSN) type.
protocol
PostgreSQL wire protocol implementation.
tls