Is it possible to share connections between a sync and async psycopg (3.x) pool?

72 Views Asked by At

I'm working on a server that is in an unfortunate state of needing both async and sync database connections, due to multiple frameworks and legacy code. I would love to be able to create one connection pool that can be used by both the sync and async engine (we use sqlalchemy), so that we don't have to needlessly create more connections to have enough for each.

Best I can tell though, AsyncConnectionPool returns AsyncConnections which do not support sync methods, and vice versa with ConnectionPool. Is there such a thing as a SyncAsyncConnectionPool or any other way to make this work?

I thought there should be a way to do this with SQLAlchemy's AsyncEngine.sync_engine but I got tons of FAILED utils/pod_points_test.py::TestPodPoints::test_timezone_handling - sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place? errors. It appears sync_engine might only be for the event system.

0

There are 0 best solutions below