Wiki source code of Configure DB2
Last modified by Eleni Cojocariu on 2026/11/25 14:43
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{warning}} | ||
| 2 | DB2 is not one of the [[databases XWiki supports>>dev:Community.SupportStrategy.DatabaseSupportStrategy]] and gets no regular testing. If what you want is a database server that is tested, the supported ones are [[MySQL>>doc:documentation.xs.admin.installation.database.configure-mysql.WebHome]], [[MariaDB>>doc:documentation.xs.admin.installation.database.configure-mariadb.WebHome]], [[PostgreSQL>>doc:documentation.xs.admin.installation.database.configure-postgresql-manually.WebHome]] and [[Oracle>>doc:documentation.xs.admin.installation.database.configure-oracle-manually.WebHome]]. | ||
| 3 | {{/warning}} | ||
| 4 | |||
| 5 | To configure XWiki to use [[IBM DB2>>https://www.ibm.com/products/db2]] on a database server you administer: | ||
| 6 | |||
| 7 | 1. Make sure you have already installed and [[configured a servlet container>>doc:documentation.xs.admin.installation.servlet-container.WebHome]] for XWiki (e.g. [[Tomcat>>doc:documentation.xs.admin.installation.servlet-container.configure-tomcat.WebHome]] or [[Jetty>>doc:documentation.xs.admin.installation.servlet-container.configure-jetty.WebHome]]), with the [[XWiki WAR>>doc:documentation.xs.admin.installation.methods.install-xwiki-war.WebHome]] file extracted/deployed. | ||
| 8 | 1. On the database machine, create an operating-system user named ##xwiki## with your usual tool, and give it a password. DB2 authenticates against operating-system users, so this is the account XWiki will connect with. The steps below use ##xwiki## as the password to keep them readable; pick a real one for anything but a test instance. | ||
| 9 | 1. Download the IBM Data Server Driver for JDBC and SQLJ, either from [[IBM>>https://www.ibm.com/support/pages/db2-jdbc-driver-versions-and-downloads]] or from the [[Maven Central repository>>https://central.sonatype.com/artifact/com.ibm.db2/jcc]], and copy its jar into the ##WEB-INF/lib## directory of the expanded XWiki WAR. XWiki ships no DB2 driver.((( | ||
| 10 | {{code language="none"}} | ||
| 11 | $ cp jcc-*.jar /path/to/webapps/xwiki/WEB-INF/lib/ | ||
| 12 | {{/code}} | ||
| 13 | ))) | ||
| 14 | 1. Open a DB2 command line processor by running ##db2##, which answers with a ##db2 =>## prompt, and create the database.((( | ||
| 15 | {{code language="none"}} | ||
| 16 | db2 => create database xwiki | ||
| 17 | {{/code}} | ||
| 18 | ))) | ||
| 19 | 1. Connect to it to continue the configuration.((( | ||
| 20 | {{code language="none"}} | ||
| 21 | db2 => connect to xwiki | ||
| 22 | {{/code}} | ||
| 23 | ))) | ||
| 24 | 1. Create a 32K bufferpool and a 32K tablespace. DB2 pages are 4K by default and a few XWiki tables have rows wider than that, so the default tablespace cannot hold them.((( | ||
| 25 | {{code language="none"}} | ||
| 26 | db2 => create bufferpool BFP32K immediate size 1024 pagesize 32k | ||
| 27 | db2 => create tablespace TSXWIKI pagesize 32k bufferpool BFP32K | ||
| 28 | {{/code}} | ||
| 29 | ))) | ||
| 30 | 1. Grant the ##xwiki## user the privileges it needs on the database and on that tablespace.((( | ||
| 31 | {{code language="none"}} | ||
| 32 | db2 => grant connect, createtab, implicit_schema on database to user xwiki | ||
| 33 | db2 => grant use of tablespace TSXWIKI to user XWIKI | ||
| 34 | {{/code}} | ||
| 35 | ))) | ||
| 36 | 1. Release the connection and leave the command line processor.((( | ||
| 37 | {{code language="none"}} | ||
| 38 | db2 => connect reset | ||
| 39 | db2 => quit | ||
| 40 | {{/code}} | ||
| 41 | ))) | ||
| 42 | 1. Edit the ##WEB-INF/hibernate.cfg.xml## file of the expanded XWiki WAR, comment out the database block that is currently active, and add the block below inside ##<session-factory>##. DB2, like SQL Server, has no commented-out block of its own in that file, so you write it rather than uncomment it. Replace ##localhost## with the host running DB2 if it is not the XWiki machine.((( | ||
| 43 | {{code language="xml"}} | ||
| 44 | <property name="hibernate.connection.url">jdbc:db2://localhost:50000/xwiki</property> | ||
| 45 | <property name="hibernate.connection.username">xwiki</property> | ||
| 46 | <property name="hibernate.connection.password">xwiki</property> | ||
| 47 | <property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property> | ||
| 48 | <property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property> | ||
| 49 | |||
| 50 | <property name="hibernate.connection.charSet">UTF-8</property> | ||
| 51 | <property name="hibernate.connection.useUnicode">true</property> | ||
| 52 | <property name="hibernate.connection.characterEncoding">utf8</property> | ||
| 53 | |||
| 54 | <mapping resource="xwiki.db2.hbm.xml"/> | ||
| 55 | <mapping resource="feeds.hbm.xml"/> | ||
| 56 | <mapping resource="instance.hbm.xml"/> | ||
| 57 | <mapping resource="notification-filter-preferences.hbm.xml"/> | ||
| 58 | <mapping resource="mailsender.hbm.xml"/> | ||
| 59 | {{/code}} | ||
| 60 | ))) | ||
| 61 | 1. Start or restart the application server. XWiki creates its tables on the first run. | ||
| 62 | 1. Verify that the tables are there, by listing the ones created under the ##XWIKI## schema.((( | ||
| 63 | {{code language="none"}} | ||
| 64 | $ db2 connect to xwiki | ||
| 65 | $ db2 "list tables for schema XWIKI" | ||
| 66 | |||
| 67 | Table/View Schema Type Creation time | ||
| 68 | ----------------- --------- ----- -------------------------- | ||
| 69 | XWIKIDOC XWIKI T 2026-10-23-19.42.11.284000 | ||
| 70 | XWIKIATTACHMENT XWIKI T 2026-10-23-19.42.12.067000 | ||
| 71 | XWIKIOBJECTS XWIKI T 2026-10-23-19.42.12.591000 | ||
| 72 | {{/code}} | ||
| 73 | ))) |