Skip to content

Commit ccad993

Browse files
Merge pull request #156 from stac-utils/backport/pool-kwargs-option
backport change from 1.2.2
2 parents 5141866 + 59bbc6f commit ccad993

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 0.8.3 (2024-02-21)
4+
5+
* enable passing `ConnectionPool` kwargs option in `titiler.pgstac.db.connect_to_db` function (author @smohiudd, #155) [backported from 1.2.2]
6+
37
## 0.8.2 (2024-01-23)
48

59
* update rio-tiler version to `>6.3.0` (defined in `titiler>=0.17`)

titiler/pgstac/db.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Database connection handling."""
22

3-
from typing import Optional
3+
from typing import Any, Dict, Optional
44

55
from fastapi import FastAPI
66
from psycopg_pool import ConnectionPool
@@ -9,22 +9,34 @@
99

1010

1111
async def connect_to_db(
12-
app: FastAPI, settings: Optional[PostgresSettings] = None
12+
app: FastAPI,
13+
settings: Optional[PostgresSettings] = None,
14+
pool_kwargs: Optional[Dict[str, Any]] = None,
1315
) -> None:
1416
"""Connect to Database."""
1517
if not settings:
1618
settings = PostgresSettings()
1719

20+
pool_kwargs = (
21+
pool_kwargs
22+
if pool_kwargs is not None
23+
else {"options": "-c search_path=pgstac,public -c application_name=pgstac"}
24+
)
25+
1826
app.state.dbpool = ConnectionPool(
1927
conninfo=str(settings.database_url),
2028
min_size=settings.db_min_conn_size,
2129
max_size=settings.db_max_conn_size,
2230
max_waiting=settings.db_max_queries,
2331
max_idle=settings.db_max_idle,
2432
num_workers=settings.db_num_workers,
25-
kwargs={"options": "-c search_path=pgstac,public -c application_name=pgstac"},
33+
kwargs=pool_kwargs,
2634
)
2735

36+
# Make sure the pool is ready
37+
# ref: https://www.psycopg.org/psycopg3/docs/advanced/pool.html#pool-startup-check
38+
app.state.dbpool.wait()
39+
2840

2941
async def close_db_connection(app: FastAPI) -> None:
3042
"""Close Pool."""

0 commit comments

Comments
 (0)