Description
Is your feature request related to a problem? Please describe.
We've observed some issues where our application hangs, though it's not necessarily certain that TCP keepalive would have prevented them.
Describe the solution you'd like
We'd like to enable TCP keepalive on our postgres client connections.
Describe alternatives you've considered
I've seen #3060 , and would agree that application-level timeouts are certainly more robust. But TCP keepalive is still useful, even once application-level timeouts are more well supported. For example, an application that's executing long-running queries might be able to detect a broken connection much more quickly with keepalive than it would with an application-level timeout. While keepalive is quite broadly supported, as pointed out in #3060 it's not universally supported. So this would need to be an option. Adding something on PgConnectionOptions
seems pretty doable, but a compile-time feature could also work.