Add native PgBouncer support to alleviate DB connection limit errors

This commit is contained in:
Keannu Christian Bernasol 2024-09-05 13:16:23 +08:00
parent 24233506c4
commit b664cb33c4
4 changed files with 48 additions and 11 deletions

View file

@ -223,16 +223,26 @@ SPECTACULAR_SETTINGS = {
WSGI_APPLICATION = 'config.wsgi.application'
# If you're using an external connection bouncer (eg. PgBouncer), server side cursors must be disabled to avoid any issues
USE_BOUNCER = get_secret("USE_BOUNCER")
if USE_BOUNCER:
DISABLE_SERVER_SIDE_CURSORS = True
DB_HOST = get_secret("DB_BOUNCER_HOST")
DB_PORT = get_secret("DB_BOUNCER_PORT")
else:
DISABLE_SERVER_SIDE_CURSORS = False
DB_HOST = get_secret("DB_HOST")
DB_PORT = get_secret("DB_PORT")
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
# Set to True to avoid issues with pgbouncer when pooling connections
'DISABLE_SERVER_SIDE_CURSORS': get_secret("DB_DISABLE_SERVER_SIDE_CURSORS"),
'DISABLE_SERVER_SIDE_CURSORS': DISABLE_SERVER_SIDE_CURSORS,
"NAME": get_secret("DB_DATABASE"),
"USER": get_secret("DB_USERNAME"),
"PASSWORD": get_secret("DB_PASSWORD"),
"HOST": get_secret("DB_HOST"),
"PORT": get_secret("DB_PORT"),
"HOST": DB_HOST,
"PORT": DB_PORT,
"OPTIONS": {
"sslmode": get_secret("DB_SSL_MODE")
},