Repository navigation
Releases
Releases · cwj2001/pgbreaker
pgbreaker v0.1.0
Initial production-ready release of pgbreaker for PostgreSQL 14–18.
Added
- Lock-free core engine (
src/core/): zero-postgres.h, zero-mallocPure C99/C11 engine with 2-cachelinePgbRuleSlotlayout,present_maskexpected-O(1) 8-level deterministic matcher on(query_id, db_oid, role_oid), quiescenteval_state-pinned concurrency CAS, single-word 64-bit GCRA smooth QPS limiter, monotonic reject-log rate limiter, and fixed 32-level per-backendPgbSlotLedger. - PostgreSQL 14–18 adapter (
src/pg/): fixed preallocated shared memory (< 256 KBat defaultmax_rules = 1024), lazy epoch-driven backend-local snapshots (zeroLWLocks on steady warm hot path), automaticEnableQueryId(), executor/portal/xact/subxact/shmem-exit unwinding,emit_log_hookserver-log suppression, and decoupled node-local atomic persistence ($PGDATA/pg_stat/pgbreaker.rules, v1 CRC32C, zero Background Worker / zero SPI / hot-standby ready). - Minimal SQL & GUC surface (
sql/pgbreaker--0.1.0.sql):- 4 GUCs:
pgbreaker.enabled,pgbreaker.shadow,pgbreaker.max_rules,pgbreaker.log_rejects. - 5 non-transactional control functions:
pgbreaker.trip(),pgbreaker.set_rule(),pgbreaker.remove_rule(),pgbreaker.clear_rules(),pgbreaker.reset_stats(). - 2 observability views:
pgbreaker.rulesandpgbreaker.status(includingpersisteddurability indicator).
- 4 GUCs:
- Packaging, CI & Chaos Demo: PGXS
Makefile, PGXNMETA.json, GitHub Actions CI matrix (C99/C11 ASan+UBSan/TSan/Release, PostgreSQL 14–18 integration/chaos/standby including PG 16 default LLVM bitcode, and end-to-end Docker chaos demo smoke test), and a self-contained 30-second Docker Compose chaos demo underdemo/.
Safety & Hardening
- Lockout protection: unconditionally exempts effective superusers, roles inheriting
pg_use_reserved_connections(PG 16+), parallel workers,EXPLAIN-only runs, nested executor statements (includingExecutorRewind), and utility/maintenance commands that do not start an executor (VACUUM,ANALYZE, DDL); supportsSIGHUPhot bypass (pgbreaker.enabled = off). - Zero-leak lease unwinding: covers normal
ExecutorEnd,ExecutorStart/Run/FinishPG_CATCH,NO SCROLLcursorMarkPortalFailedvia portal cleanup hooks, returnedrefcursordeferred admission,SAVEPOINTabort/commit reparenting,pg_cancel_backend,pg_terminate_backend, andbefore_shmem_exit. - Least-privilege & install hardening:
CREATE EXTENSION pgbreakerverifies superuser ownership, zero non-superuserCREATEprivileges, and an empty schema (no pre-existing relations, functions, or types); revokesPUBLICaccess across all extension objects, enforcessuperuser()in C on mutators, grants read-only views topg_read_all_stats, and redacts$PGDATAinpersist_pathunlesspg_read_all_settingsis held. - Fail-Open persistence: protects against non-regular/FIFO/symlink state files (
O_NONBLOCK | O_NOFOLLOW), preserves oversized files whenmax_rulesis lowered until explicitclear_rules(), and suppresses53P01server error spam viaemit_log_hook.
Verification
- Core engine: 17/17 standalone tests across Clang C99/C11 ASan+UBSan, Clang C99/C11 TSan (64-thread stress), and GCC
-O2Release (0warnings,0leaks,0data races). - PostgreSQL 14–18: 12/12 integration, zero-leak chaos, Extended Query (
PQexecParams) /PREPARE,pg_stat_statementsbidirectional co-loading, restart/crash durability, read-only hot-standby, andpgbenchsuites (413assertions;11/11/408assertions inSKIP_BENCH=1CI mode,0leaks).