-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python Postgres - Should I manually close connections ? #1869
Comments
You should reuse connections. ADBC does not implement connection pooling. Use a dedicated connection pooling library on top of ADBC connections. |
Hello, Thanks for your reply. I couldn't find resources on this. Should I use psycopg for the connection pooling ? |
I don't think in general DBAPI drivers are expected to implement connection pooling, so it's not really a consideration in the first place. I'm not sure psycopg's pool will work with anything except psycopg. SQLAlchemy and others provide connection pools, but which one you want to use will depend on your application. |
I think what we can do here is demo how to use a connection pool (like SQLAlchemy) with the ADBC drivers in the documentation. |
There's now an example here: #1919 |
Very interesting, thank you |
What would you like help with?
Hello,
I have recently started using
adbc_driver_postgresql
andadbc-driver-manager
along with pandasread_sql
to query data from a Postgres database.With SQLalchemy, everyone mentions the Connection Pool that should help with my case, but no trace of a Connection Pool in the ADBC docs.
When my python webapp starts, several different database requests are made, most to the same table.
I do not know what are the best practices or the most efficient way to handle ADBC connections.
Should I use a context manager and close the connection after one use everytime ?
This is the recommended use in the Pandas documentation (above 2.2.0)
However, the
dbapi.connect
is long, always longer than the actualread_sql
(see attached image for a profiling example), and is executed everytime.Should I just leave the connection open ?
Should I cache the connection resource ?
I'm sure that like any engineering problem there are tradeoffs to all of these, but I do not have comparison points here apart from execution time
thanks !
Environment:
The text was updated successfully, but these errors were encountered: