aiondb-pgwire

PostgreSQL wire protocol (v3) implementation. Provides a TCP listener, the startup and SSL request handshakes, the simple query protocol, the extended query protocol (Parse / Bind / Describe / Execute / Sync) including text and binary formats, and SQLSTATE-aware error mapping. The server is generic over any type implementing aiondb_engine::PgWireEngine.

cargo

[dependencies]
aiondb-pgwire = { path = "../aiondb-pgwire" }

modules

ModulePurpose
codecLow-level binary frame reader/writer.
messagesTyped frontend and backend message structs.
connectionPer-client connection state machine.
serverTCP listener and connection-spawning entry point.
formatValue-to-text serialization for the PostgreSQL text format.
binary_formatValue-to-bytes serialization for the binary format.
engine_poolBounded blocking dispatcher used to call into the engine from async tasks.
replicationLogical/physical replication endpoints.
tlsTlsConfig and acceptor construction (validate_tls_config, build_tls_acceptor).

key types

TypeRole
server::PgWireServer<E>The TCP server. Constructed with PgWireServer::new (TLS-aware) or PgWireServer::new_plain.
server::PgWireConfigListen address, port, connection limits, per-IP limits, startup and shutdown timeouts, idle timeout, auth-failure backoff, engine pool config, optional TlsConfig, require_tls, fail_on_weak_rng, max_portals.
server::CancelRegistryMaps (pid, secret_key) to a SessionHandle for CancelRequest handling.
server::ServerMetrics, server::ServerMetricsSnapshotAtomic counters for accepted connections, active connections, queries, startups, and authentication failures.
server::ServerHealthState, server::ServerHealthSnapshotServer health view used by the observability HTTP endpoint.
tls::TlsConfig, tls::validate_tls_configTLS material and validation.
engine_pool::EnginePoolBounded blocking dispatcher used internally by PgWireServer.

example

use std::sync::Arc;
use aiondb_engine::EngineBuilder;
use aiondb_pgwire::server::{PgWireConfig, PgWireServer};
use tokio::sync::watch;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let engine = Arc::new(
        EngineBuilder::new_in_memory()
            .build()
            .expect("build engine"),
    );

    let config = PgWireConfig {
        bind_address: "127.0.0.1".into(),
        port: 5432,
        require_tls: false,
        ..Default::default()
    };

    let server = PgWireServer::new_plain(engine, config);
    let (_tx, rx) = watch::channel(false);
    server.start(rx).await
}