feat: Add small pool for PostgreSQL connections to allow multiple docker instances communicating with PostgreSQL

This commit is contained in:
Igor Ilic 2025-09-09 18:15:33 +02:00
parent ba33dca592
commit b1e47d9e0d

View file

@ -12,7 +12,6 @@ from sqlalchemy import NullPool, text, select, MetaData, Table, delete, inspect
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
from cognee.modules.data.models.Data import Data
from cognee.modules.sync.models.SyncOperation import SyncOperation
from cognee.shared.logging_utils import get_logger
from cognee.infrastructure.utils.run_sync import run_sync
from cognee.infrastructure.databases.exceptions import EntityNotFoundError
@ -58,7 +57,11 @@ class SQLAlchemyAdapter:
)
else:
self.engine = create_async_engine(
connection_string, pool_size=12, max_overflow=12, poolclass=None
connection_string,
pool_size=1, # one physical session per container
max_overflow=1,
pool_recycle=280, # keep below RDS 300 s idle kill
pool_pre_ping=True,
)
self.sessionmaker = async_sessionmaker(bind=self.engine, expire_on_commit=False)