配置连接池

This commit is contained in:
zk
2026-07-15 16:14:31 +08:00
parent 54e415b5aa
commit ca227ebef7
5 changed files with 30 additions and 2 deletions
+7
View File
@@ -6,6 +6,8 @@ PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=feAeyR0u2fJGSS5ooFdHnSbyHQNY4WlV
PG_DB=postgres
PG_POOL_SIZE=10
PG_MAX_OVERFLOW=10
# MySQL(业务库)
DB_HOST=8.163.14.142
@@ -13,6 +15,11 @@ DB_PORT=30006
DB_USER=root
DB_PASSWORD=^CgDatabase2020
DB_NAME=offerpie
MYSQL_POOL_SIZE=10
MYSQL_MAX_OVERFLOW=10
# 连接池获取连接等待超时(秒),两库共用
DB_POOL_TIMEOUT=30
# AI 供应商
+7
View File
@@ -6,6 +6,8 @@ PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=feAeyR0u2fJGSS5ooFdHnSbyHQNY4WlV
PG_DB=postgres
PG_POOL_SIZE=10
PG_MAX_OVERFLOW=10
# MySQL(业务库)
DB_HOST=8.163.14.142
@@ -13,6 +15,11 @@ DB_PORT=30006
DB_USER=root
DB_PASSWORD=^CgDatabase2020
DB_NAME=offerpie
MYSQL_POOL_SIZE=10
MYSQL_MAX_OVERFLOW=10
# 连接池获取连接等待超时(秒),两库共用
DB_POOL_TIMEOUT=30
# AI 供应商
+7
View File
@@ -6,6 +6,8 @@ PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=feAeyR0u2fJGSS5ooFdHnSbyHQNY4WlV
PG_DB=postgres
PG_POOL_SIZE=10
PG_MAX_OVERFLOW=10
# MySQL(业务库)
DB_HOST=192.168.31.105
@@ -13,6 +15,11 @@ DB_PORT=3306
DB_USER=root
DB_PASSWORD=123456
DB_NAME=offerpie
MYSQL_POOL_SIZE=10
MYSQL_MAX_OVERFLOW=10
# 连接池获取连接等待超时(秒),两库共用
DB_POOL_TIMEOUT=30
# AI 供应商
+5 -2
View File
@@ -14,7 +14,7 @@ class Settings(BaseSettings):
pg_password: str = ""
pg_db: str = "postgres"
pg_pool_size: int = 10
pg_max_overflow: int = 20
pg_max_overflow: int = 10
# ──────────── MySQL(业务库)────────────
db_host: str = "192.168.31.105"
@@ -23,7 +23,10 @@ class Settings(BaseSettings):
db_password: str = "123456"
db_name: str = "offerpie"
mysql_pool_size: int = 10
mysql_max_overflow: int = 20
mysql_max_overflow: int = 10
# 连接池获取连接的等待超时(秒),两个数据源共用
db_pool_timeout: int = 30
# ──────────── AI 供应商 ────────────
# 火山引擎(OpenAI 兼容风格)
+4
View File
@@ -39,7 +39,9 @@ async def init_db() -> None:
settings.pg_url,
pool_size=settings.pg_pool_size,
max_overflow=settings.pg_max_overflow,
pool_timeout=settings.db_pool_timeout,
pool_recycle=3600,
pool_pre_ping=True,
echo=False,
)
_pg_session_factory = async_sessionmaker(_pg_engine, expire_on_commit=False)
@@ -48,7 +50,9 @@ async def init_db() -> None:
settings.mysql_url,
pool_size=settings.mysql_pool_size,
max_overflow=settings.mysql_max_overflow,
pool_timeout=settings.db_pool_timeout,
pool_recycle=3600,
pool_pre_ping=True,
echo=False,
)
_mysql_session_factory = async_sessionmaker(_mysql_engine, expire_on_commit=False)