I've seen https://github.com/psycopg/psycopg2/issues/369 and I was wondering if the status has changed, and if not what is the currently recommanded way to handle that ?
This question on stackoverflow has several answers , but they all start to date a bit:
http://stackoverflow.com/questions/1281875/making-sure-that-psycopg2-database-connection-alive
So I was wondering if it could be included in the documentation how to handle this situation , especially as I think it's quite common in web services.
You may check conn.get_transaction_status() to detect a broken connection after an operation. For an example check the pool code
There is no way to know if there is an error _before_ performing an operation, if not... performing an operation. For this reason it is not implemented in the driver. If your app can afford performing an extra roundtrip per request you may query a select 1 on the connection before using it.
ok thanks, for the "select 1" , yes, actually I was wondering if there was some mechanism in the postgresql's protocol like the 'ping' in mysql's, but it seems not.