fix: add pool_pre_ping and pool_recycle to prevent connection errors
This commit is contained in:
parent
bd8ba302a8
commit
4c294965f2
|
|
@ -6,7 +6,14 @@ from .config import settings
|
|||
# Convert sync URL to async
|
||||
DATABASE_URL = settings.DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://")
|
||||
|
||||
engine = create_async_engine(DATABASE_URL, echo=settings.DEBUG, pool_size=10, max_overflow=20)
|
||||
engine = create_async_engine(
|
||||
DATABASE_URL,
|
||||
echo=settings.DEBUG,
|
||||
pool_size=10,
|
||||
max_overflow=20,
|
||||
pool_pre_ping=True, # Test connection before using
|
||||
pool_recycle=3600 # Recycle connections after 1 hour
|
||||
)
|
||||
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
Base = declarative_base()
|
||||
|
|
|
|||
Loading…
Reference in New Issue