強化 CD Gunicorn 掛載與 metrics 降噪
All checks were successful
CD Pipeline / deploy (push) Successful in 9m26s
All checks were successful
CD Pipeline / deploy (push) Successful in 9m26s
This commit is contained in:
15
docs/memory/db_connection_pool_singleton_20260430.md
Normal file
15
docs/memory/db_connection_pool_singleton_20260430.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# DB Connection Pool Singleton Hotfix (2026-04-30)
|
||||
|
||||
## 背景
|
||||
|
||||
`/daily_sales` 出現 PostgreSQL `FATAL: sorry, too many clients already`。根因不是單一查詢過重,而是多個 route 會在 request 內直接呼叫 `DatabaseManager()`,舊實作每次初始化都 `create_engine()`,導致同一個 worker process 內反覆建立新的 SQLAlchemy connection pool。
|
||||
|
||||
## 修正
|
||||
|
||||
`database/manager.py` 的 `DatabaseManager` 以 `(DATABASE_TYPE, effective_db_path)` 作為 key 快取 `engine` 與 `Session` factory。後續直接 `DatabaseManager()` 會共用同一組連線池,不再持續放大 PostgreSQL client 數。
|
||||
|
||||
## 維運提醒
|
||||
|
||||
- 若再次遇到 `too many clients already`,先檢查是否有新模組繞過 `database.manager.get_db_manager()` 或直接 `create_engine()`。
|
||||
- 熱修後需重啟 `momo-pro-system`,讓舊 process 釋放既有連線池。
|
||||
- 不需要重啟或重建 `momo-db`。
|
||||
Reference in New Issue
Block a user