Configuring a datasource connection
New Confluence installation
1. Stop Confluence
In the Confluence setup wizard, you'll be prompted to choose your database. At this point, you should:
- Use
bin/stop-confluence.sh
orbin/stop-confuence.bat
to stop Confluence. - Back up the following files, in case you need to revert your changes:
<installation-directory>/conf/server.xml
<installation-directory>/confluence/WEB-INF/web.xml
<home-directory>/confluence.cfg.xml
2. Add your database driver
Copy your database driver into the <installation-directory>/lib
directory.
Here's where to find the driver for your database:
- PostgreSQL: bundled with Confluence at
<installation-directory>/confluence/WEB-INF/lib/postgresql-x.x.x.jar
- Microsoft SQL Server: bundled with Confluence at
<installation-directory>/confluence/WEB-INF/lib/mssql-jdbc-x.x.x.x.jar
- MySQL: head to Database JDBC Drivers to download the driver
- Oracle: head to Database JDBC Drivers to download the driver
3. Configure the datasource in Tomcat
Next, add the datasource configuration to Tomcat.
- Edit
<installation-directory>/conf/server.xml
Find the following lines:
<Context path="" docBase="../confluence" debug="0" reloadable="true"> <!-- Logger is deprecated in Tomcat 5.5. Logging configuration for Confluence is specified in confluence/WEB-INF/classes/log4j.properties -->
Insert the following DataSource
Resource
element for your specific database directly after the lines above (inside theContext
element, directly after the opening<Context.../>
line, beforeManager)
.
Replace<database-user>
,<password>
,<host>
and<database-name>
(or<SID>
for Oracle) with details of your own database. You may also need to change the port, if your database server is not running on the default port.Configure the connection pool and other properties. See the Apache Tomcat 8 Datasource documentation for more information.
- If you plan to use collaborative editing, you'll need to make sure:
- You're using a supported database driver. Collaborative editing will fail if you're using an unsupported or custom JDBC driver or
driverClassName
in your datasource. See Database JDBC Drivers for the list of drivers we support. - Your database connection pool allows enough connections to support both Confluence and Synchrony (which defaults to a maximum pool size of 15)
- You're using simple username and password authentication for your database.
- You're using a supported database driver. Collaborative editing will fail if you're using an unsupported or custom JDBC driver or
4. Configure the Confluence web application
Configure Confluence to use this datasource:
- Edit
.<CONFLUENCE_INSTALLATION>/
confluence/WEB-INF/web.xml Insert the following element just before
</web-app>
near the end of the file:<resource-ref> <description>Connection Pool</description> <res-ref-name>jdbc/confluence</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
5. Restart Confluence and continue setup process
Now that your datasource is configured, you can continue with the setup wizard.
- Use
bin/start-confluence.sh
orbin/start-confuence.bat
to restart Confluence - Go to
http://localhost:8090
to return to the setup wizard. - When prompted choose My own database > Datasource.
- Enter the JNDI name of your datasource, for example,
java:comp/env/jdbc/confluence
- Follow the prompts to finish setting up Confluence.
Existing Confluence installation
If you want to switch from using a direct JDBC connection to a datasource:
- Stop Confluence.
- Back up the following files, in case you need to revert your changes:
<installation-directory>/conf/server.xml
<installation-directory>/confluence/WEB-INF/web.xml
<home-directory>/confluence.cfg.xml
- Follow the steps above for a new installation and copy your driver and add the datasource to the appropriate files. You can find the details of your current database connection in
<home-directory>/confluence.cfg.xml
. Edit the
file and remove any line that contains a property that begins with<home-directory>/
confluence.cfg.xmlhibernate
.Insert the following at the start of the
<properties>
section.<property name="hibernate.setup"><![CDATA[true]]></property> <property name="hibernate.dialect"><![CDATA[com.atlassian.hibernate.dialect.MySQLDialect]]></property> <property name="hibernate.connection.datasource"><![CDATA[java:comp/env/jdbc/confluence]]></property>
- Restart Confluence.
Upgrading Confluence with a datasource
If you're upgrading Confluence (manually or using the installer) you will need to:
- Stop Confluence (if you have attempted to start it).
- Copy your database driver into the
<installation-directory>/lib
directory. - Edit
<installation-directory>/conf/server.xml
and add your datasource resource. - Edit
<installation-directory>/confluence/WEB-INF/web.xml
to configure Confluence to use this datasource.
If you forget to do these steps, Confluence will not start up after upgrade and you'll see the following error:
HTTP Status 500 - Confluence is vacant, a call to tenanted [public abstract org.hibernate.Session org.hibernate.SessionFactory.getCurrentSession() throws org.hibernate.HibernateException] is not allowed.