From f99e407d6e6fd6c52867706396af5ad30205101e Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Mon, 20 May 2024 20:37:04 +0300 Subject: [PATCH] Add experimental max_connections config --- config.yaml | 4 ++++ src/charm.py | 8 +++++++- src/config.py | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 158ef85875..35617edbab 100644 --- a/config.yaml +++ b/config.yaml @@ -402,3 +402,7 @@ options: Allowed values are: from 0 to 2000000000. type: int default: 150000000 + experimental_max_connections: + type: int + description: | + [EXPERIMENTAL] Force set max_connections. diff --git a/src/charm.py b/src/charm.py index 67eb66ae4a..ab887a52ee 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1547,8 +1547,14 @@ def update_config(self, is_creating_backup: bool = False) -> bool: logger.warning("Early exit update_config: Cannot connect to Postgresql") return False + # Use config value if set, calculate otherwise + if self.config.experimental_max_connections: + max_connections = self.config.experimental_max_connections + else: + max_connections = max(4 * os.cpu_count(), 100) + self._patroni.bulk_update_parameters_controller_by_patroni({ - "max_connections": max(4 * os.cpu_count(), 100), + "max_connections": max_connections, "max_prepared_transactions": self.config.memory_max_prepared_transactions, }) diff --git a/src/config.py b/src/config.py index 6627a67b32..c8196b46ba 100644 --- a/src/config.py +++ b/src/config.py @@ -98,6 +98,7 @@ class CharmConfig(BaseConfigModel): vacuum_autovacuum_vacuum_cost_delay: Optional[float] vacuum_autovacuum_vacuum_scale_factor: Optional[float] vacuum_vacuum_freeze_table_age: Optional[int] + experimental_max_connections: Optional[int] @classmethod def keys(cls) -> list[str]: