Repository navigation
Store: one connection pool per process for the Postgres backend - #227
Merged
Merged
Conversation
… one DSN — one server, one role, one TLS setting — borrows from a process-wide pool: a connection per statement, or one pinned for the length of a transaction and returned on commit or rollback. So N memories in a process hold at most P connections between them, an idle memory holds none, and the telemetry sidecar and the broker's blob door ride the same pool rather than dialling their own.
sathish-mg
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #181, the third and final increment. #195 made the bootstrap lock
transaction-scoped; #205 schema-qualified every statement so nothing rode
the session's search_path. With that done, nothing about a connection
belonged to a memory any more — but each handle still owned one (plus a
second for telemetry), so a worker holding a thousand memories held a
thousand or two thousand connections against a max_connections sized in the
low hundreds. The documented remedy was a host-side LRU of handles, which is
exactly what Areev Cloud's spec asks to remove.
What changes
PgPool), keyed by the DSN with thestore's own
schema/provision/poolparameters stripped. A handleborrows a connection per statement (
with_conn), or pins one for atransaction (
begin→commit/rollback,Droprolls back a forgottenone). An idle handle holds nothing.
?pool=P/$AREEV_PG_POOL, default 8, the DSN winning; callers pastthe cap wait in FIFO order rather than fail. The first open sizes the
pool; a later open naming another size is reported in
open_warnings().cleared past 512) and the ANN GUCs live on
PooledConn. The handle keepsonly what it wants:
txn_preludeapplies it withSET LOCALafterBEGIN,
align_sessionreconciles it onto the borrowed connection outsideone. The bootstrap's
search_pathisSET LOCAL, so no pooled sessionkeeps a schema.
outside a transaction replays once, a write never. Concurrent
first-openers converge on the
CREATE SCHEMArace (Postgres documents IFNOT EXISTS DDL as racy; the shared runtime widened the window at a small
pool).
read_blob_offline's Postgres door go throughthe same pool. The pool's runtime is a small multi-thread runtime (a
current-thread one would serialise its block_on callers into a
process-wide lock); it stays private to the store behind the sync Db seam.
Proof (local Postgres 16 + PgBouncer 1.25.2)
?pool=2under parallel load; chaos, stale and pool binaries at
?pool=2.skip is a role-auth test needing password forwarding the throwaway
trust-mode PgBouncer lacks; it passes on direct Postgres).
tests/pg_pool.rs: N handles ≤ P connections, counted inpg_stat_activitybyapplication_name = areev.memories_in_one_process_share_nothing: two memories served in turn byone pool share nothing across grains, recall, text, vectors, meta, blobs.
cargo test --workspace2,732 passed; clippy clean onpostgresandpostgres-tls; default build/clippy clean; repo-stats within tolerance.?pool=2against the postgresservice.
Docs moved with the code:
docs/deployment-profile.md(connections andpooler sections rewritten, the LRU advice withdrawn),
docs/docker.md,docs/cookbook.md, the storeCLAUDE.md, anARCHITECTURE.md§10decision, and the changelog.