Expand description
Postgres wire endpoint. Trust by default; MD5 with pgwire_users;
TLS with pgwire_tls_cert + pgwire_tls_key. Non-loopback binds
require pgwire_allow_remote = true.
StructsΒ§
- Active
Cursor π - Conn
State π - Cursor
Inner π - State that shares the cursorβs lifetime: the portal, the leftover-row
buffer, and the exhausted flag. Held by
Arcso a row stream can keep reading afterConnState::getreturns. - Failure
Tracker π - Rolling-window auth-failure count per peer IP.
- Laminar
Auth πSource - Per-call salt + stored credential for the MD5 challenge flow. The
stored value is either plaintext (legacy) or
md5<32-hex>, the same format Postgresβpg_authiduses, where the hex ismd5(password β user). The pre-hashed form lets operators avoid plaintext at rest. - Laminar
Handler Factory - Laminar
Pgwire Handler - Laminar
Query Parser - Resolves SQL to
LaminarStmt, looking up stream schemas against the liveLaminarDBso the extended-queryDescribereturns columns without running the query. - TlsConfig
Paths π - Owned counterpart to
TlsPathsthat the listener keeps for the lifetime ofserve()so the file watcher can rebuild the acceptor without the original config still being in scope. - TlsPaths
- TlsReload
State - Live TLS acceptor + paths needed to rebuild it on cert rotation.
Reads on the accept path are a single mutex acquire and a cheap
TlsAcceptorclone; reloads are triggered by the file watcher.
EnumsΒ§
- Fetch
Target π - Laminar
Stmt - Parsed statement carried through
ParseβBindβExecute. - Startup
Auth π - Startup-phase dispatch.
Md5requires password auth;Trustaccepts any connection. Selected once at listener startup based on whetherpgwire_usersis non-empty. - TlsMin
Version - Minimum TLS protocol version accepted on the pgwire listener. rustls already disables TLS 1.0/1.1; this narrows further when an operator needs TLS 1.3 only.
ConstantsΒ§
- MAX_
TRACKED_ πIPS
FunctionsΒ§
- apply_
set π SEThandling. We thread plainSET name = valueto the engineβs session-property store, and refuseSET TRANSACTION-class statements since we donβt honor isolation levels.- arrow_
to_ πpg_ type - build_
client_ πcert_ verifier - check_
cert_ πexpiry - Reject certs past
notAfter; warn within 30 days. - classify_
outcome π - Stable audit code for a sessionβs exit status.
- driver_
select_ πresponse - Handle the
SELECTs drivers issue at connect time. Single literal,SELECT version(), andSELECT current_schema()are answered inline. Anything else is rejected β real queries belong on/api/v1/sql. - encode_
batch π - encode_
field_ πbinary - Binary-encode a single Arrow value via
postgres-typesToSql. - encode_
field_ πtext - encode_
row π - engine_
metadata_ πresponse - Run a SHOW through the engine and stream its
RecordBatchto the wire. - ensure_
tls_ πprovider - Idempotent install of aws-lc-rs as rustlsβ default provider.
- fetch_
direction_ πcount FETCH NEXTand bareFETCH FORWARDmap to a single row, matching PG.- fetch_
response π - Strict-PG FETCH: blocks until
targetrows are produced, the pump exits, or the broadcast lags. Lag/exit flipscursor.inner.exhaustedso the nextevict_idle_peerreaps the cursor. Text format only; SimpleQuery has no binary. Leftover rows from a multi-row frame stay incursor.inner.pendingso successive FETCHes consume the frame in order. - field_
infos π - Build pgwire
FieldInfos from an Arrow schema.result_format(from aBind) sets per-column text/binary;Nonedefaults all-text. - handle_
close π - handle_
declare_ πcursor - Open a SUBSCRIBE behind a cursor name. Rejects with 42P03 if the name is
already in use on this connection (matches PG; user must
CLOSEfirst). - handle_
fetch π - list_
text_ πelements - Owned elements of a
List<Utf8|LargeUtf8>row, NULLs preserved. - load_
tls_ πacceptor - open_
portal_ πfor_ subscribe - outer_
md5_ πchallenge - MD5 challenge response when only the inner hash is known: the client
sends
md5{hex(md5(inner_hex || salt))}and the server precomputes the same string for comparison. - parse_
pre_ πhashed_ md5 - If
storedis apg_authid-style pre-hash, return the inner hex (the bit after themd5tag). Lowercase hex only; uppercase or other lengths fall back to plaintext handling. - pg_
text_ πarray_ literal - Postgres
text[]literal, e.g.{"en","ja",NULL}. Every element is quoted (NULL excepted) so commas/braces/quotes in values are unambiguous. - record_
batch_ πresponse - serve
- show_
sql π - Reconstruct a single SHOW statement from the parsed variant. Used by the
pgwire dispatcher so a multi-statement query (
SHOW SOURCES; SHOW SINKS) re-executes only the matching statement, not the whole input string. - standard_
or_ πcursor_ response - Wraps the original
standard_responseand intercepts cursor / transaction statements that need ConnState. Anything else falls through to the existing handler unchanged. - standard_
response π - Connection-setup statements: transaction control,
SET, and a tiny set of catalog probes drivers send during handshake. Anything DDL/DML hits the βuse HTTPβ error. - stream_
subscribe_ πflushing - Stream a SUBSCRIBE, flushing the
Sinkafter every batch. - subscription_
query_ πresponse - Wrap a
SubscriptionPortalin a pgwireResponse::Queryso the framework can chunk viaExecute(max_rows)and emit PortalSuspended automatically. Used by the chunked extended-query path. - text_
response π - Single-row
textresponse with one column. - try_
reload_ πtls - Rebuild the TLS acceptor from
state.pathsand atomically swap it in. On any error the previous acceptor is left in place, so a bad rotation (truncated file, expired cert) doesnβt take TLS down. - unsupported_
select π - user_
error π - value_
to_ πu64 - warn_
if_ πkey_ world_ readable - Warn if the key file is group/other-readable.
- watch_
tls_ πfiles - Watch the cert / key / client-CA files and call
try_reload_tlsafter debounced changes. Mirrors the pattern inwatcher.rs(parent-dir watch, debounce, then act). Runs until the channel closes; the caller drives shutdown by aborting the task that owns this future.
Type AliasesΒ§
- Md5Handler π