Skip to content

Commit e24f5b4

Browse files
🎨 Make POSTGRES_MINSIZE and POSTGRES_MAXSIZE configurable (#8199)
Co-authored-by: matusdrobuliak66 <[email protected]> Co-authored-by: Dustin Kaiser <[email protected]>
1 parent 15204d5 commit e24f5b4

File tree

17 files changed

+48
-34
lines changed

17 files changed

+48
-34
lines changed

.env-devel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ POSTGRES_HOST=postgres
194194
POSTGRES_PASSWORD=adminadmin
195195
POSTGRES_PORT=5432
196196
POSTGRES_USER=scu
197-
197+
POSTGRES_MINSIZE=2 # see https://github.com/ITISFoundation/osparc-simcore/pull/8199
198+
POSTGRES_MAXSIZE=50
198199
POSTGRES_READONLY_PASSWORD=readonly
199200
POSTGRES_READONLY_USER=postgres_readonly
200201

packages/postgres-database/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def sync_engine(postgres_service: str) -> Iterable[sqlalchemy.engine.Engine]:
8181
def _make_asyncpg_engine(postgres_service: str) -> Callable[[bool], AsyncEngine]:
8282
# NOTE: users is responsible of `await engine.dispose()`
8383
dsn = postgres_service.replace("postgresql://", "postgresql+asyncpg://")
84-
minsize = 1
84+
minsize = 2
8585
maxsize = 50
8686

8787
def _(echo: bool):

packages/service-library/src/servicelib/db_asyncpg_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ async def create_async_engine_and_database_ready(
3030
raise_if_migration_not_ready,
3131
)
3232

33-
server_settings = None
33+
server_settings = {
34+
"jit": "off"
35+
} # see https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#disabling-the-postgresql-jit-to-improve-enum-datatype-handling
3436
if settings.POSTGRES_CLIENT_NAME:
3537
assert isinstance(settings.POSTGRES_CLIENT_NAME, str) # nosec
36-
server_settings = {
37-
"application_name": settings.POSTGRES_CLIENT_NAME,
38-
}
38+
server_settings.update(
39+
{
40+
"application_name": settings.POSTGRES_CLIENT_NAME,
41+
}
42+
)
3943

4044
engine = create_async_engine(
4145
settings.dsn_with_async_sqlalchemy,

packages/service-library/tests/aiohttp/with_postgres/test_aiopg_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def test_create_pg_engine(postgres_service_with_fake_data: DataSourceName)
7878
dsn = postgres_service_with_fake_data
7979

8080
# using raw call and dsn.asdict to fill create_engine arguments!
81-
engine1 = await aiopg.sa.create_engine(minsize=1, maxsize=5, **asdict(dsn))
81+
engine1 = await aiopg.sa.create_engine(minsize=2, maxsize=5, **asdict(dsn))
8282

8383
# just creating engine
8484
engine2 = await create_pg_engine(dsn)
@@ -114,7 +114,7 @@ async def test_engine_when_idle_for_some_time():
114114
database="db",
115115
application_name="test-app",
116116
)
117-
engine = await create_pg_engine(dsn, minsize=1, maxsize=1)
117+
engine = await create_pg_engine(dsn, minsize=2, maxsize=2)
118118
init_pg_tables(dsn, metadata)
119119
assert not engine.closed # does not mean anything!!!
120120
# pylint: disable=no-value-for-parameter

packages/settings-library/src/settings_library/postgres.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class PostgresSettings(BaseCustomSettings):
3131

3232
# pool connection limits
3333
POSTGRES_MINSIZE: Annotated[
34-
int, Field(description="Minimum number of connections in the pool", ge=1)
35-
] = 1
34+
int, Field(description="Minimum number of connections in the pool", ge=2)
35+
] = 2 # see https://github.com/ITISFoundation/osparc-simcore/pull/8199
3636
POSTGRES_MAXSIZE: Annotated[
37-
int, Field(description="Maximum number of connections in the pool", ge=1)
37+
int, Field(description="Maximum number of connections in the pool", ge=2)
3838
] = 50
3939

4040
POSTGRES_CLIENT_NAME: Annotated[
@@ -124,7 +124,7 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
124124
"POSTGRES_USER": "usr",
125125
"POSTGRES_PASSWORD": "secret",
126126
"POSTGRES_DB": "db",
127-
"POSTGRES_MINSIZE": 1,
127+
"POSTGRES_MINSIZE": 2,
128128
"POSTGRES_MAXSIZE": 50,
129129
"POSTGRES_CLIENT_NAME": "my_app", # first-choice
130130
"HOST": "should be ignored",

packages/settings-library/tests/data/.env-compact

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
APP_HOST=localhost
44
APP_PORT=80
55
APP_OPTIONAL_ADDON='{"MODULE_VALUE": 10, "MODULE_VALUE_DEFAULT": 42}'
6-
APP_REQUIRED_PLUGIN='{"POSTGRES_HOST": "localhost", "POSTGRES_PORT": 5432, "POSTGRES_USER": "foo", "POSTGRES_PASSWORD": "**********", "POSTGRES_DB": "foodb", "POSTGRES_MINSIZE": 1, "POSTGRES_MAXSIZE": 50, "POSTGRES_CLIENT_NAME": "None"}'
6+
APP_REQUIRED_PLUGIN='{"POSTGRES_HOST": "localhost", "POSTGRES_PORT": 5432, "POSTGRES_USER": "foo", "POSTGRES_PASSWORD": "**********", "POSTGRES_DB": "foodb", "POSTGRES_MINSIZE": 2, "POSTGRES_MAXSIZE": 50, "POSTGRES_CLIENT_NAME": "None"}'

packages/settings-library/tests/data/.env-granular

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ POSTGRES_PASSWORD=**********
1313
# Database name
1414
POSTGRES_DB=foodb
1515
# Minimum number of connections in the pool
16-
POSTGRES_MINSIZE=1
16+
POSTGRES_MINSIZE=2
1717
# Maximum number of connections in the pool
1818
POSTGRES_MAXSIZE=50
1919
# Name of the application connecting the postgres database, will default to use the host hostname (hostname on linux)

packages/settings-library/tests/data/.env-mixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ POSTGRES_PASSWORD=**********
1313
# Database name
1414
POSTGRES_DB=foodb
1515
# Minimum number of connections in the pool
16-
POSTGRES_MINSIZE=1
16+
POSTGRES_MINSIZE=2
1717
# Maximum number of connections in the pool
1818
POSTGRES_MAXSIZE=50
1919
# Name of the application connecting the postgres database, will default to use the host hostname (hostname on linux)

packages/settings-library/tests/data/.env-sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ POSTGRES_PASSWORD=secret
99
# Database name
1010
POSTGRES_DB=foodb
1111
# Maximum number of connections in the pool
12-
POSTGRES_MINSIZE=1
12+
POSTGRES_MINSIZE=2
1313
# Minimum number of connections in the pool
1414
POSTGRES_MAXSIZE=50
1515

packages/settings-library/tests/test_base_w_postgres.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class _FakePostgresSettings(BaseCustomSettings):
5555
POSTGRES_PASSWORD: str
5656

5757
POSTGRES_DB: str
58-
POSTGRES_MINSIZE: Annotated[int, Field(ge=1)] = 1
59-
POSTGRES_MAXSIZE: Annotated[int, Field(ge=1)] = 50
58+
POSTGRES_MINSIZE: Annotated[int, Field(ge=2)] = 2
59+
POSTGRES_MAXSIZE: Annotated[int, Field(ge=2)] = 50
6060

6161
POSTGRES_CLIENT_NAME: Annotated[
6262
str | None,
@@ -200,7 +200,7 @@ def test_parse_from_individual_envs(
200200
"POSTGRES_PASSWORD": "shh",
201201
"POSTGRES_DB": "db",
202202
"POSTGRES_MAXSIZE": 50,
203-
"POSTGRES_MINSIZE": 1,
203+
"POSTGRES_MINSIZE": 2,
204204
"POSTGRES_CLIENT_NAME": None,
205205
}
206206
}
@@ -215,7 +215,7 @@ def test_parse_from_individual_envs(
215215
"POSTGRES_PASSWORD": "shh",
216216
"POSTGRES_DB": "db",
217217
"POSTGRES_MAXSIZE": 50,
218-
"POSTGRES_MINSIZE": 1,
218+
"POSTGRES_MINSIZE": 2,
219219
"POSTGRES_CLIENT_NAME": None,
220220
}
221221
}
@@ -262,7 +262,7 @@ def test_parse_compact_env(
262262
"POSTGRES_PASSWORD": "shh2",
263263
"POSTGRES_DB": "db2",
264264
"POSTGRES_MAXSIZE": 50,
265-
"POSTGRES_MINSIZE": 1,
265+
"POSTGRES_MINSIZE": 2,
266266
"POSTGRES_CLIENT_NAME": None,
267267
}
268268
}
@@ -372,7 +372,7 @@ def test_parse_from_mixed_envs(
372372
"POSTGRES_PASSWORD": "shh2",
373373
"POSTGRES_DB": "db2",
374374
"POSTGRES_MAXSIZE": 50,
375-
"POSTGRES_MINSIZE": 1,
375+
"POSTGRES_MINSIZE": 2,
376376
"POSTGRES_CLIENT_NAME": None,
377377
}
378378
}

0 commit comments

Comments
 (0)