mirror of
https://github.com/suitenumerique/docs
synced 2026-04-21 13:37:20 +00:00
🔧(backend) add DB_PSYCOPG_POOL_ENABLED settings
The psycopg pool config was enabled by default forcing its usage. Using psycopg pool can be difficult, finding the good configuration take time. By default its usage should be disable and the maintainer of the instance should decide to enable it or not.
This commit is contained in:
parent
0c17d76f60
commit
73a7c250b5
6 changed files with 73 additions and 21 deletions
1
.github/workflows/impress.yml
vendored
1
.github/workflows/impress.yml
vendored
|
|
@ -143,7 +143,6 @@ jobs:
|
|||
AWS_S3_ENDPOINT_URL: http://localhost:9000
|
||||
AWS_S3_ACCESS_KEY_ID: impress
|
||||
AWS_S3_SECRET_ACCESS_KEY: password
|
||||
DB_PSYCOPG_POOL_MAX_SIZE: 15
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
|
|
|
|||
|
|
@ -6,12 +6,16 @@ and this project adheres to
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
## [v4.8.0] - 2026-03-13
|
||||
### Added
|
||||
|
||||
- 🔧(backend) add DB_PSYCOPG_POOL_ENABLED settings
|
||||
|
||||
### Changed
|
||||
|
||||
- ⬇️(backend) downgrade django-treebeard to version < 5.0.0
|
||||
|
||||
## [v4.8.0] - 2026-03-13
|
||||
|
||||
### Added
|
||||
|
||||
- ✨(backend) add a is_first_connection flag to the User model #1938
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ These are the environment variables you can set for the `impress-backend` contai
|
|||
| DB_NAME | Name of the database | impress |
|
||||
| DB_PASSWORD | Password to authenticate with | pass |
|
||||
| DB_PORT | Port of the database | 5432 |
|
||||
| DB_PSYCOPG_POOL_ENABLED | Enable or not the psycopg pool configuration in the default database options | False |
|
||||
| DB_PSYCOPG_POOL_MIN_SIZE | The psycopg min pool size | 4 |
|
||||
| DB_PSYCOPG_POOL_MAX_SIZE | The psycopg max pool size | None |
|
||||
| DB_PSYCOPG_POOL_TIMEOUT | The default maximum time in seconds that a client can wait to receive a connection from the pool | 3 |
|
||||
|
|
|
|||
|
|
@ -9,4 +9,3 @@ DB_NAME=impress
|
|||
DB_USER=dinum
|
||||
DB_PASSWORD=pass
|
||||
DB_PORT=5432
|
||||
DB_PSYCOPG_POOL_MAX_SIZE=15
|
||||
|
|
|
|||
|
|
@ -28,3 +28,39 @@ def test_invalid_settings_oidc_email_configuration():
|
|||
"Both OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION and "
|
||||
"OIDC_ALLOW_DUPLICATE_EMAILS cannot be set to True simultaneously. "
|
||||
)
|
||||
|
||||
|
||||
def test_settings_psycopg_pool_not_enabled():
|
||||
"""
|
||||
Test that not changing DB_PSYCOPG_POOL_ENABLED should not configure psycopg in the DATABASES
|
||||
settings.
|
||||
"""
|
||||
|
||||
class TestSettings(Base):
|
||||
"""Fake test settings without enabling psycopg"""
|
||||
|
||||
TestSettings.post_setup()
|
||||
|
||||
assert TestSettings.DATABASES["default"].get("OPTIONS") == {}
|
||||
|
||||
|
||||
def test_settings_psycopg_pool_enabled(monkeypatch):
|
||||
"""
|
||||
Test when DB_PSYCOPG_POOL_ENABLED is set to True, the psycopg pool options should be present
|
||||
in the DATABASES OPTIONS.
|
||||
"""
|
||||
|
||||
monkeypatch.setenv("DB_PSYCOPG_POOL_ENABLED", "True")
|
||||
|
||||
class TestSettings(Base):
|
||||
"""Fake test settings without enabling psycopg"""
|
||||
|
||||
TestSettings.post_setup()
|
||||
|
||||
assert TestSettings.DATABASES["default"].get("OPTIONS") == {
|
||||
"pool": {
|
||||
"min_size": 4,
|
||||
"max_size": None,
|
||||
"timeout": 3,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,24 +99,7 @@ class Base(Configuration):
|
|||
"localhost", environ_name="DB_HOST", environ_prefix=None
|
||||
),
|
||||
"PORT": values.Value(5432, environ_name="DB_PORT", environ_prefix=None),
|
||||
"OPTIONS": {
|
||||
# https://www.psycopg.org/psycopg3/docs/api/pool.html#psycopg_pool.ConnectionPool
|
||||
"pool": {
|
||||
"min_size": values.IntegerValue(
|
||||
4, environ_name="DB_PSYCOPG_POOL_MIN_SIZE", environ_prefix=None
|
||||
),
|
||||
"max_size": values.IntegerValue(
|
||||
None,
|
||||
environ_name="DB_PSYCOPG_POOL_MAX_SIZE",
|
||||
environ_prefix=None,
|
||||
),
|
||||
"timeout": values.IntegerValue(
|
||||
3,
|
||||
environ_name="DB_PSYCOPG_POOL_TIMEOUT",
|
||||
environ_prefix=None,
|
||||
),
|
||||
}
|
||||
},
|
||||
# Psycopg pool can be configured in the post_setup method
|
||||
}
|
||||
}
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
|
|
@ -1017,6 +1000,36 @@ class Base(Configuration):
|
|||
"OIDC_ALLOW_DUPLICATE_EMAILS cannot be set to True simultaneously. "
|
||||
)
|
||||
|
||||
psycopg_pool_enabled = values.BooleanValue(
|
||||
False, environ_name="DB_PSYCOPG_POOL_ENABLED", environ_prefix=""
|
||||
)
|
||||
|
||||
if psycopg_pool_enabled:
|
||||
cls.DATABASES["default"].update(
|
||||
{
|
||||
"OPTIONS": {
|
||||
# https://www.psycopg.org/psycopg3/docs/api/pool.html#psycopg_pool.ConnectionPool
|
||||
"pool": {
|
||||
"min_size": values.IntegerValue(
|
||||
4,
|
||||
environ_name="DB_PSYCOPG_POOL_MIN_SIZE",
|
||||
environ_prefix=None,
|
||||
),
|
||||
"max_size": values.IntegerValue(
|
||||
None,
|
||||
environ_name="DB_PSYCOPG_POOL_MAX_SIZE",
|
||||
environ_prefix=None,
|
||||
),
|
||||
"timeout": values.IntegerValue(
|
||||
3,
|
||||
environ_name="DB_PSYCOPG_POOL_TIMEOUT",
|
||||
environ_prefix=None,
|
||||
),
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class Build(Base):
|
||||
"""Settings used when the application is built.
|
||||
|
|
|
|||
Loading…
Reference in a new issue