Update: I should have tested before posting: you don’t need to set up the
logging, you simply need to pass echo_pool=True to create_engine().
/Update
If you ever need to see what SQLAlchemy is doing with the connection pool (like when it seems to be exhausting the pool for no apparent reason), it is useful to enable logging to see what SQLA is doing with the connections in the pool.
It’s actually quite easy to do, however the
docs
say that you should set all echo flags to False: ignore this. Instead,
make sure you have the echo_pool=True keyword argument to create_engine()
set or the logging won’t work.
A working snippet might then be:
import sqlalchemy
import sqlalchemy.orm
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.DEBUG)
engine = sqlalchemy.create_engine('postgres://test', echo_pool=True)
You should now get quite a lot of output from SQLAlchemy in regards to its pool manipulation.