Skip to main content

Module postgres

Module postgres 

Source
Expand description

PostgreSQL wire protocol compatibility layer (Phase 3.1 PG parity).

Exposes a minimal subset of the PG v3 protocol so psql, JDBC drivers (pgjdbc), node-postgres, pgAdmin, DBeaver, and friends can connect to RedDB as if it were PostgreSQL.

§Scope (Phase 3.1)

  • Startup message negotiation (protocol version 3.0 / 196608).
  • Authentication: trust only (no password). Clients that send an actual password are accepted — the password is ignored.
  • Simple query protocol (Q frames): parse → execute → stream rows.
  • Extended query protocol (Parse / Bind / Describe / Execute / Close / Sync), including prepared statements, portals, ParameterDescription, and row-limited Execute with PortalSuspended.
  • Minimal row description using a small OID mapping table.
  • ReadyForQuery + Command­Complete + ErrorResponse framing.
  • TLS: SSLRequest is answered with 'S' and the connection is upgraded via a rustls handshake when the listener carries TLS material, sharing the native wire’s cert/key config (PgWireConfig::tls). Without TLS material SSLRequest is declined with 'N' and the client continues in plaintext. A cleartext password is only challenged over an encrypted link or a loopback bind (see authenticate_startup).

Not in this phase (future 3.1.x):

  • SASL / SCRAM auth, GSSAPI encryption.
  • Function-call protocol.
  • COPY protocol.
  • NOTIFY / LISTEN.

Modules§

protocol
PostgreSQL v3 wire protocol message framing (Phase 3.1 PG parity).
server
PostgreSQL wire-protocol listener (Phase 3.1 PG parity).
types
PostgreSQL type OID mapping (Phase 3.1 PG parity).

Structs§

PgWireConfig
Startup-tuned configuration for the PG wire listener.

Enums§

BackendMessage
Backend (server → client) messages we emit.
FrontendMessage
Frontend (client → server) messages we parse.
PgOid
A subset of PG type OIDs that cover every case we need to encode.
PgWireError
Error type surfaced by the framing layer. Wraps IO errors plus structural validation failures (bad message tag, truncated frame).

Functions§

start_pg_wire_listener
Spawn the PG wire listener. Blocks until the listener errors out. Each connection is handled in its own tokio task.
value_to_pg_wire_bytes
Encode a Value as the UTF-8 text representation PG’s text-mode protocol expects. Binary format is opt-in via a flag in the client’s Bind message — we don’t advertise binary support yet, so simple text encoding is sufficient for every supported client.