How to stop database sleeping

I am getting an exception when calling database code after a period of inactivity

java.sql.SQLNonTransientConnectionException: Could not read resultset: Connection reset at org.mariadb.jdbc.internal.SQLExceptionMapper.get( at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException( at org.mariadb.jdbc.MySQLStatement.executeQueryEpilog( at org.mariadb.jdbc.MySQLStatement.execute( at org.mariadb.jdbc.MySQLStatement.executeQuery( at org.mariadb.jdbc.MySQLStatement.executeQuery( at org.apache.commons.dbcp.DelegatingStatement.executeQuery( at org.apache.commons.dbcp.DelegatingStatement.executeQuery( at com.vimba.database.DBFactory.attemptLoginWithTempPasswordDetails( at com.vimba.database.DBFactory.authenticate( at com.vimba.service.ExposedFunctions.login( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at$1.invoke( at$2.invoke( at at at at at at at$2.process( at$HttpToolkit.handle( at at at at at javax.servlet.http.HttpServlet.service( at javax.servlet.http.HttpServlet.service( at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( at org.apache.catalina.core.ApplicationFilterChain.doFilter( at org.apache.catalina.core.StandardWrapperValve.invoke( at org.apache.catalina.core.StandardContextValve.invoke( at at org.apache.catalina.core.StandardHostValve.invoke( at org.apache.catalina.valves.ErrorReportValve.invoke( at org.apache.catalina.core.StandardEngineValve.invoke( at org.apache.catalina.connector.CoyoteAdapter.service( at org.apache.coyote.http11.Http11Processor.process( at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process( at$ at Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not read resultset: Connection reset at org.mariadb.jdbc.internal.mysql.MySQLProtocol.getResult( at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery( at org.mariadb.jdbc.MySQLStatement.execute( ... 40 more Caused by: Connection reset

I have tried to change the /etc/my.cnf to add a wait_timeout of a week but it has not made a difference;

[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock

  1. Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
  2. Settings user and group are ignored when systemd is used.
  3. If you need to run mysqld under a different user or group,
  4. customize your systemd unit file for mysqld/mariadb according to the
  5. instructions in
  1. Currently, there are mariadb and community-mysql packages in Fedora.
  2. This particular config file is included in respective RPMs of both of them,
  3. so the following settings are general and will be also used by both of them.
  4. Otherwise the RPMs would be in conflict.
  5. Settings for particular implementations like MariaDB are then
  6. defined in appropriate sections; for MariaDB server in [mariadb] section in
  7. /etc/my.cnf.d/server.cnf (part of mariadb-server).
  8. It doesn't matter that we set these settings only for [mysqld] here,
  9. because they will be read and used in mysqld_safe as well. log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/


  1. include all files from the config directory
  2. !includedir /etc/my.cnf.d
  1. one week timeout to see if exception goes wait_timeout=604800

event_scheduler=on /etc/my.cnf (END)

Can someone suggest how to stop this please?

Answer Answered by Steel Brain in this comment.

You might want to ping the database periodically. after lets say every 30 seconds. a single query like `select 1` to keep the connection alive works well.


Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.