Search code examples
postgresqlsessionpsycopg2blaze

How to close a DB session when opened with Blaze


In the Docs it was mentioned how to open a connection to a DB with Blaze's Data.

db = Data('postgresql:///user:pass@hostname')

I did like above and then got the following message when I try to do any update operations (like drop table) on that DB with a session opened via Psycopg2 afterwards.

DETAIL:  There is 1 other session using the database.

As I'm making taking care of the sessions that I'm opening with Psycopg2, I suspect this behaviour is because of Blaze. (Please correct, if I'm wrong).

How can I close this Blaze session or connection first when I'm done, so that I can do other stuff with Psycopg2, for example?


Solution

  • This has been answered in the Blaze mailing list here. (Blaze uses sqlalchemy to interact with Postgres. By accessing its engine at db.data, we can manage our active connections.)