Skip to content

Commit

Permalink
Add experimental max_connections config
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed May 20, 2024
1 parent ce38466 commit f99e407
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 7 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit f99e407

Please sign in to comment.