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

Show last authors
1 When running XWiki with a relational database in Docker using [[Docker Run>>doc:documentation.xs.admin.installation.methods.install-xwiki-docker.docker-run.WebHome]], the configuration depends on the database engine used. MySQL and MariaDB share similar behavior, while PostgreSQL differs in several aspects.
2
3 == Character Encoding and Collation ==
4
5 XWiki requires the database to store text as UTF-8 and to compare it case-sensitively. Database containers do not do this by default, which is why the examples pass extra options when starting them. These options are not optional, and they only take effect when the database itself is created, so they must be in place before the database container is started for the first time.
6
7 For MySQL and MariaDB, the server is started with {{code language="none"}}--character-set-server=utf8mb4{{/code}} and {{code language="none"}}--collation-server=utf8mb4_bin{{/code}}. The ##utf8mb4## character set covers the whole Unicode range, including characters outside the Basic Multilingual Plane such as emoji, and the binary collation compares strings byte by byte, so values differing only in case, such as two page names, stay distinct.
8
9 For PostgreSQL, the ##POSTGRES_INITDB_ARGS## environment variable is set to {{code language="none"}}--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8{{/code}}. The encoding covers the whole Unicode range, and the builtin ##C.UTF-8## locale orders text by code point rather than by language rules. With a language-dependent order, PostgreSQL sorts document names differently from Solr, and XWiki then re-indexes a large part of the wiki at every restart. The builtin locale provider requires PostgreSQL 17 or later.
10
11 == MySQL and MariaDB ==
12
13 [[Run XWiki (MySQL on Tomcat) Using Docker Run>>doc:documentation.xs.admin.installation.methods.install-xwiki-docker.docker-run.run-xwiki-mysql-tomcat.WebHome]] and [[Run XWiki (MariaDB on Tomcat) Using Docker Run>>doc:documentation.xs.admin.installation.methods.install-xwiki-docker.docker-run.run-xwiki-mariadb-tomcat.WebHome]] use a similar initialization and storage model.
14
15 When starting a container for the database, it is common to mount two directories:
16
17 * One directory is used during database initialization to provide SQL files, such as permission setup scripts.
18 * One directory is used to store the database data files so that the database content is preserved when the container is stopped, removed, or restarted.
19
20 The initialization SQL file (##init.sql## inside ##/my/path/mysql-init## or ##/my/path/mariadb-init##) grants additional privileges to the XWiki database user. This allows the user to create new databases, which is required for features such as sub-wikis.
21
22 When mounting directories into the container, always use fully-qualified absolute paths. Relative paths may lead to unexpected behavior depending on how Docker is executed.
23
24 == PostgreSQL ==
25
26 PostgreSQL follows a different approach compared to MySQL and MariaDB.
27
28 [[Run XWiki (PostgreSQL on Tomcat) Using Docker Run>>doc:documentation.xs.admin.installation.methods.install-xwiki-docker.docker-run.run-xwiki-postgresql-tomcat.WebHome]] mounts a single directory, used to persist the database data files. Its path inside the container changed in PostgreSQL 18.
29
30 No initialization script is mounted, because XWiki stores each sub-wiki as a schema of the same database rather than as a separate database: the database user owns that database and can already create schemas, so there are no extra privileges to grant. Creating the database and its user is handled entirely through [[environment variables>>doc:documentation.xs.admin.installation.methods.install-xwiki-docker.configuration.environment-variables.WebHome]].
31
32 == Connecting to the Database from the Command Line ==
33
34 To run SQL queries against the XWiki database, start a database client inside the database container. Find the name or id of that container with ##docker ps##, or with ##docker compose ps## when you started XWiki with Docker Compose, and pass the values you set for ##DB_USER##, ##DB_PASSWORD## and ##DB_DATABASE## (all three are ##xwiki## in the examples).
35
36 For MySQL:
37
38 {{code language="bash"}}
39 docker exec -it <container> mysql --user=xwiki --password=xwiki xwiki
40 {{/code}}
41
42 For MariaDB, use the ##mariadb## client, as the MariaDB image no longer provides a ##mysql## command:
43
44 {{code language="bash"}}
45 docker exec -it <container> mariadb --user=xwiki --password=xwiki xwiki
46 {{/code}}
47
48 For PostgreSQL:
49
50 {{code language="bash"}}
51 docker exec -it <container> psql --username=xwiki xwiki
52 {{/code}}
53
54 You can also open a shell inside the container with ##docker exec -it <container> bash## and run the client from there.

Get Connected