It is possible to set keepalives specifically on the PostgreSQL connection, per https://www.postgresql.org/docs/10/libpq-connect.html#LIBPQ-PARAMKEYWORDS (which psycopg2 accepts as keyword parameters IIRC). It should be functionally the same as setting system-wide TCP settings, but might be easier to rollout as a fix (just a software update, no need to change system settings).
It is possible to set keepalives specifically on the PostgreSQL connection, per https:/ /www.postgresql .org/docs/ 10/libpq- connect. html#LIBPQ- PARAMKEYWORDS (which psycopg2 accepts as keyword parameters IIRC). It should be functionally the same as setting system-wide TCP settings, but might be easier to rollout as a fix (just a software update, no need to change system settings).