Does the pre ping feature in SqlAlchemy db pools automatically reconnect and send the SQL command in case the pre ping check fails?
Asked Answered
Z

1

6

I want some clarification on how the pre ping feature exactly works with SqlAlchemy db pools. Let's say I try to make a SQL query to my database with the db pool. If the db pool sends a pre ping to check the connection and the connection is broken, does it automatically handle this? By handling I mean that it reconnects and then sends the SQL query? Or do I have to handle this myself in my code?

Thanks!

Zecchino answered 18/3, 2021 at 13:37 Comment(0)
W
8

From the docs, yes stale connections are handled transparently:

The calling application does not need to be concerned about organizing operations to be able to recover from stale connections checked out from the pool.

... unless:

If the database is still not available when “pre ping” runs, then the initial connect will fail and the error for failure to connect will be propagated normally. In the uncommon situation that the database is available for connections, but is not able to respond to a “ping”, the “pre_ping” will try up to three times before giving up, propagating the database error last received.

Walston answered 18/3, 2021 at 22:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.