Surviving Database Connection Closures

When a database server reboots or a network failure has occurred, all connections in the database connection pool are broken. To overcome this issue, Confluence would normally need to be restarted. To avoid this situation Confluence uses a validation query to check a database connection is alive before attempting to use it.  If a broken connection is detected in the pool, a new one is created to replace it.

This validation query is enabled by default on new installations (from Confluence 6.5 and later), but if you've upgraded from an older Confluence version you can enable this manually by following the steps below. 

While there are several different ways to perform this validation query, we recommend letting the database driver choose how to validate if a connection is still alive, rather than overriding the driver configuration with a specific validation query. 


Enable validation query with a direct JDBC connection

To ensure Confluence validates database connections in the database connection pool:

  1. Stop Confluence. 
  2. Edit the <home-directory>confluence.cfg.xml file.
  3. Insert the following property in the <properties> block.

    <property name="hibernate.c3p0.validate">true</property>
  4. Save confluence.cfg.xml

  5. Restart Confluence. 

You should now be able to recover from a complete loss of all connections in the database connection pool without the need to restart Confluence.

Enable validation query with a datasource connection

To ensure Confluence validates database connections in the database connection pool:

  1. Stop Confluence.

  2. Edit the <installation-directory>/conf/server.xml file (or wherever you have configured your datasource).
  3. Find the Resource element for your data source, and add the "testOnBorrow" parameter as in the example for PostgreSQL below.  Remember to give it the appropriate value for your database type. 

    server.xml (excerpt)
    ... 
    <Resource name="jdbc/confluence" auth="Container" type="javax.sql.DataSource"
              username="postgres"
              password="postgres"
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://localhost:5432/yourDatabaseName"
              maxTotal="60"
              maxIdle="20"
              testOnBorrow="true" />
    ...
  4. Save conf/server.xml

  5. Restart Confluence.

You should now be able to recover from a complete loss of all connections in the database connection pool without the need to restart Confluence.

Last modified on Apr 13, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.