Out-of-the-box the embedded Jackrabbit repository used by Sling (the Embedded Jackrabbit Repository bundle) uses Derby to persist the JCR nodes and properties. For some applications or environments it may be required or required to replace Derby with another backing store such as PostgreSQL or Oracle.
This page is based on the journey of Tony Giaccone to get Sling running with a PostgreSQL based Jackrabbit instance.
To replace Derby as the persistence manager for Jackrabbit the following steps are required:
- Provide a JDBC driver for your database as an OSGi bundle
- Reconfigure Jackrabbit to use your database
- (Re-) Start the Embedded Jackrabbit bundle
When you are not using the Derby persistence manager, you may safely remove the Derby bundle from your Sling instance.
The hardest thing to do is probably getting the JDBC driver for your database. One option is to look at the bundles provided by Spring Source in their repository at http://www.springsource.com/repository/.
Another option is to create the bundle on your own using Peter Kriens' BND Tool:
- Get the JDBC driver for your database from the driver provider
- Wrap the JDBC driver library into an OSGi bundle:
- Deploy the driver to your local Maven 2 Repository (Required if adding the JDBC driver to a Maven build, e.g. using the Sling Launchpad Plugin)
Tony reports no success with the Spring Source bundle, whily the BND approach worked for the PostgreSQL JDBC driver.
To replace Derby in a running Sling instance follow these steps (e.g. through the Web Console at /system/console):
- Uninstall the Apache Derby bundle
- Install the JDBC bundle prepared in the first step
- Stop the Jackrabbit Embedded Repository bundle\
This needs to be reconfigured and restarted anyway. So lets just stop it to prevent failures in the next step.
- Refresh the packages (click the Refresh Packages button)
Alternatively, you may wish to stop Sling after uninstalling Derby and installing the JDBC bundle. Technically, this is not required, though.
To actually use a persistence manager other than the default (Derby) persistence manager, you have to configure Jackrabbit to use it. Create a repository.xml file in the sling/jackrabbit folder before starting Sling for the first time. If the repository was already started, you can also modify the existing file.
To prepare a repository.xml file before first startup, use the repository.xml as a template and modify it by replacing the <PersistenceManager> elements to refer to the selected persistence manager.
If the file already exists, you can modifiy this existing file and there is no need to get the original from the SVN repository.
For example to use PostgreSQL instead of Derby modify the <PersistenceManager> elements as follows:
Modify the url, user, and password parameters to match your database setup.
If you reconfigure Jackrabbit to use the new persistence manager, the existing repository data in the sling/jackrabbit directory, except the repository.xml file, of course, should now be removed.
Finally either start Sling or start the Jackrabbit Embedded Repository bundle.
This description is based on Tony Giaccone's description Swapping Postgres for Derby sent to the Sling Users mailing list.