KC + MariaDB on Linux + casefolding

35 views
Skip to first unread message

Lucio Crusca

unread,
Apr 21, 2022, 7:54:29 AM4/21/22
to Keycloak User
MariaDB on Debian GNU/Linux (or any other distro with ext4 by default), is case sensitive for table and database names, because the underlying default filesystem is ext4, which in turn, by default, is case sensitive.

Installing KC on bare metal following the official docs here and then moving it to MariaDB for production leads to a broken install, caused by the missing casefolding in the database. During startup you get this kind of error messages.

I don't know if this is documented somewhere and I couldn't find it or if it is obvious hence not documented, but I feel like a little note in the docs could have helped me out a lot.

Anyway, after many trials and errors that eventually led me to deduce that casefolding was the culprit, I was able to move KC to MariaDB with the folloing steps:

  1. update your kernel to at least release 5.2 built with CONFIG_UNICODE=y (for Debian that means at least 5.13)
  2. create a ext4 filesystem to hold the MariaDB databases using the casefold options: `mkfs -t ext4 -O casefold -E encoding_flags=strict /dev/...`
  3. configure fstab to mount that filesystem on /srv/databases
  4. configure MariaDB to store databases in a subdirectory of that filesystem: `datadir=/srv/databases/mariadb`
  5. configure MariaDB to ignore case when querying: `lower_case_table_names=2` 
  6. stop MariaDB, move databases from /var/lib/mysql to /srv/databases/mariadb and start MariaDB again
  7. Setup KC to use MariaDB and enjoy

Lucio Crusca

unread,
Apr 21, 2022, 7:58:33 AM4/21/22
to Keycloak User
Forgot to report step 3.1... create /srv/databases/mariadb with +F attribute: `mkdir -p /srv/databases/mariadb && chown mysql:mysql /srv/databases/mariadb && chattr +F /srv/databases/mariadb`
Reply all
Reply to author
Forward
0 new messages