After several hours of uptime on a new dedicated server, my Minecraft server would lose connection to the database and throw the following error: "org.postgresql.util.PSQLException: This connection has been closed."
After restarting the MC server, it would be fine again but the issue would continue after several hours again. My guess is that it's losing connection over time somehow. Currently the ping between the dedicated host and the host where the database is on ranges between 0.3 - 0.5ms.
I create the connection instance with a PGSimpleDataSource after setting the values from a config.
PGSimpleDataSource ds = new PGSimpleDataSource();
// Set the values here...
Connection c = ds.getConnection(...);
Does anyone know why this happens and/or if there is a fix to this? Thank you!
If it is not a bug in the client software, it could be a firewall or router misconfiguration.
Set tcp_keepalives_idle
in postgresql.conf
to a value less than the default of 2 hours, for example 300 for 5 minutes. After you reload PostgreSQL, it will automatically send keepalive packets every 5 minutes, keeping the connection from getting idle.
If that does not solve the problem, then it must be a bug in the client application.