Problem Statement: Customer is restarting PostgreSQL database every night. Long running jobs are failing from after DB restart.
Just to save the trouble of scanning through the PostgreSQL driver release notes, the Connection.setNetworkTimeout() was released in version 42.2.0 of the driver (https://jdbc.postgresql.org/documentation/changelog.html#version_42.2.0)
Check when database was restarted
To get the start time, execute the query below:
psql -c “SELECT pg_postmaster_start_time();”
To get the uptime, execute the query below:
psql -c “SELECT now() – pg_postmaster_start_time();”
Exception Handling for guaranteed write:
boolean writeStatus = false;
write to database;
writeStatus = true;
}catch (Exception ex)
sleep for 30 seconds;
//Hope for db to recover.