Wiki source code of Configure PostgreSQL Manually

Last modified by superadmin on 2026/11/25 20:42

Show last authors
1 To configure PostgreSQL for XWiki:
2
3 1. Make sure you have already installed and [[configured a servlet container>>doc:documentation.xs.admin.installation.deploy-servlet-container.WebHome]] for XWiki (e.g. [[Tomcat>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-tomcat.WebHome]] or [[Jetty>>doc:documentation.xs.admin.installation.deploy-servlet-container.configure-jetty.WebHome]]), with the [[XWiki WAR>>doc:documentation.xs.admin.installation.methods.install-xwiki-war.WebHome]] file extracted/deployed.
4 1. Install [[PostgreSQL>>https://www.postgresql.org/]]. Make sure you download a [[supported version>>dev:Community.SupportStrategy.DatabaseSupportStrategy]].
5 1. Download the [[PostgreSQL JDBC driver>>https://jdbc.postgresql.org/download/]].
6 1. Copy the JDBC driver JAR into the XWiki web application's ##WEB-INF/lib## directory of the [[servlet container>>doc:documentation.xs.admin.installation.deploy-servlet-container.WebHome]], or into the container's common library directory.
7 1. Start PostgreSQL.
8 1. Create the XWiki database.(((
9 {{code language="sql"}}
10 CREATE DATABASE xwiki
11 WITH OWNER = postgres
12 ENCODING = 'UNICODE'
13 LOCALE_PROVIDER = 'builtin'
14 LOCALE = 'C.UTF-8'
15 TABLESPACE = pg_default
16 TEMPLATE = template0;
17 {{/code}}
18
19 On PostgreSQL versions before 17, omit the ##LOCALE_PROVIDER## line and use ##LOCALE = 'C.utf8'##.
20 )))
21 1. Verify that the database was created and is listed in the available databases:(((
22 {{code language="none"}}
23 \l
24 {{/code}}
25 )))
26 1. Connect to the XWiki database.(((
27 {{code language="none"}}
28 \connect xwiki
29 {{/code}}
30 )))
31 1. Create the XWiki database user.(((
32 {{code language="sql"}}
33 CREATE USER xwiki PASSWORD 'xwiki' VALID UNTIL 'infinity';
34 {{/code}}
35 )))
36 1. Verify that the user was created.(((
37 {{code language="none"}}
38 \du
39 {{/code}}
40 )))
41 1. Grant database privileges to the XWiki user.(((
42 {{code language="sql"}}
43 GRANT ALL PRIVILEGES ON DATABASE xwiki TO xwiki;
44 {{/code}}
45 )))
46 1. Grant schema privileges to the XWiki user.(((
47 {{code language="sql"}}
48 GRANT ALL ON SCHEMA public TO xwiki;
49 {{/code}}
50 )))
51 1. Comment out the configuration section of the database currently active in the ##WEB-INF/hibernate.cfg.xml## file of the expanded XWiki WAR.
52 1. Uncomment the "##PostgreSQL configuration##" section of the same file, in full, including the mapping entries at its end.(((
53 {{code language="xml"}}
54 <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/xwiki</property>
55 <property name="hibernate.connection.username">xwiki</property>
56 <property name="hibernate.connection.password">xwiki</property>
57 <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
58 <property name="hibernate.jdbc.use_streams_for_binary">false</property>
59 <property name="xwiki.virtual_mode">schema</property>
60
61 <property name="hibernate.connection.charSet">UTF-8</property>
62 <property name="hibernate.connection.useUnicode">true</property>
63 <property name="hibernate.connection.characterEncoding">utf8</property>
64
65 <mapping resource="xwiki.postgresql.hbm.xml"/>
66 <mapping resource="feeds.hbm.xml"/>
67 {{/code}}
68 )))
69 1. Review the ##hibernate.connection.url## property, and the user name and password, against the database you created.
70 1. Start XWiki.
71 1. Open your wiki in a browser. XWiki connects to PostgreSQL, creates its tables on first start, and serves the wiki without a database error.

Get Connected