Dependency-free Postgres client primitives for Zig (std.Io-native, TLS, simple + extended protocol, pipelining).
This is a library. For a tiny runnable client, see examples/smoke.zig.
- Build the smoke client:
zig build example-smoke - Run tests:
zig build test - Run the full benchmark suite:
zig build benchmark - Run only the latency suite:
zig build benchmark-latency - Run only the throughput suite:
zig build benchmark-throughput - Override benchmark settings:
zig build benchmark -- --mode throughput --throughput-workers 8 --throughput-per-worker 20000 --throughput-pipeline-depth 256 --sql "select 1"
Latency runs the one-request-at-a-time paths. Throughput runs the pipeline paths by default.
The benchmark suite starts a temporary local PostgreSQL instance and compares:
zpgsimple-query modezpgextended-query modezpgsimple-pipeline modezpgextended-pipeline mode- a C++
libpqpipeline-mode shim
Requirements for benchmarking:
/usr/bin/initdb/usr/bin/pg_ctllibpqheaders and library available to the Zig C++ build
zpg.Config.parseUri(...)zpg.Conn.connect(...)zpg.Pool.init(...)zpg.Pool.initUri(...)conn.query(...)/pool.query(...)conn.queryValues(...)/pool.queryValues(...)conn.exec(...)/pool.exec(...)conn.execValues(...)/pool.execValues(...)conn.prepare(...)conn.pipeline(...)
- startup + authentication
- PostgreSQL SSL negotiation backed by Zig std TLS
- cleartext, MD5, and SCRAM-SHA-256 auth
- simple query protocol
- extended protocol with prepared statements
- pipelined simple and extended query execution on one connection
- fixed-size lazy connection pool
- text and binary result decoding
- pool only reuses connections that are healthy and back in idle transaction state
- connections left inside a transaction are discarded on release instead of being reused
connect_timeoutis parsed from the URI but currently ignored on Zig0.16.0-dev, becausestd.Io.netstill panics when a TCP connect timeout is passed through- the Docker TLS integration test is present, but currently auto-skips on this Zig toolchain when std TLS fails PostgreSQL interop with
TlsUnexpectedMessage/EndOfStream
- client certificates
Zig std currently exposes server-side TLS verification for std.crypto.tls.Client, but not a public API for supplying a client certificate/private key pair, so mTLS client auth is not implemented in zpg yet.