I have a postgres database in the background that could be on high load sometimes
to automatically reconnect
High load of the database server can not be the reason to “loose connection”. CUBA application uses connection pool in front of the database and re-uses several connections many times. Connection pools do reconnection when necessary.
Which connection pool do you use?
Default tomcat’s connection pool (commons dbcp 2) has a number of options which you can use to quickly recover after connection to database server has been lost and then restored, such as “testOnBorrow”, “removeAbandoned” etc.