Conversation
This was referenced Aug 14, 2026
esoergel
force-pushed
the
es/projectdb-pool-sizing
branch
2 times, most recently
from
August 14, 2026 14:18
d089750 to
5774de4
Compare
3 tasks
MartinRiese
force-pushed
the
es/projectdb-pool-sizing
branch
from
September 17, 2026 19:11
5774de4 to
5abec1a
Compare
ProjectDB uses a user for each domain, and pgbouncer keys its pools by (user, database), so that's a pool per domain. Add a max_db_connections setting to create a cap across all domains.
Picks up pgbouncer_max_db_connections, null everywhere since no test
environment sets it.
Regenerated with:
python -c "import sys; sys.path.insert(0, '.'); \
from tests.test_postgresql_config import update_configs; update_configs()"
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Doc updates in this commit explain the change
MartinRiese
force-pushed
the
es/projectdb-pool-sizing
branch
from
September 18, 2026 14:28
5abec1a to
2e5349c
Compare
1 task
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.
These three stacked PRs introduce a database-level safeguard that keeps a Project DB query from reading another domain's data, even if the query layer above it has a bug or is handed hostile SQL.
Part I: HQ Query Users (#6962)
Each domain gets its own postgres role, which has read-only access to only that domain's tables. Queries on behalf of that domain are authenticated as that user, so postgres enforces separation between tenants.
HQ provisions these query users using a constrained
SECURITY DEFINERfunction calledprojectdb_provision_rolewhich narrowly defines the action. This function is created during database provisioning. Passwords are derived from the domain name viadjango.utils.crypto.salted_hmac, never stored.Part II: PgBouncer
PgBouncer connection pooling complicates things in two ways
Part IIa: PGBouncer Authentication (#6963)
PgBouncer authenticates queries itself, so it has to know user passwords. Currently, it validates against a file called
userlist.txtwhich is managed by commcare-cloud. Adding a new user requires amending that file, which just isn't doable in this context. Instead, we give pgbouncer anauth_queryit can run to get the username and password to authenticate a user that's not inuserlist.txt.To do this, we need a few things in place:
user_lookupfunction as described in the pgbouncer docs (https://www.pgbouncer.org/config.html), supporting theauth_queryauth_userpgbouncer can authenticate as when running theauth_query, and a password for that useruser_lookupfunctionPart IIb: (This PR)
PgBouncer keys its pools by
(user, database)pair, meaning that each domain will have it's own pool in pgbouncer. Right now, we allow up to 490 open connections per pool (default_pool_size). Since ProjectDB uses many pools, we can instead set amax_db_connectionsas a limit across all ProjectDB pools, and set a much lowerpool_sizeto prevent one domain from claiming all that for itself.Environments Affected
Staging, since it has
project_dbconfigured already. Should only affect other environments when that's enabled.Announce New Release
No. Shouldn't require action by anyone but me.