I want to understand when this error occurs and how to resolve it. I checked pg_stat_activity
and pg_locks
but couldnt figure out which process is exhausing the connections
We are using sqlalchemy to connect to database as below
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine_url = f'{dbms}://{username}:{password}@{hostname}:{port}/{database}'
engine = create_engine(engine_url, pool_size=20, max_overflow=10)
Session = sessionmaker(bind=engine)
db_session = Session()
This is an extension of Heroku "psql: FATAL: remaining connection slots are reserved for non-replication superuser connections"