Files
website-hadow.fr/_posts/2025-11-02-nextcloud-collation-version-mismatch.md
2025-11-16 22:27:51 +01:00

55 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
layout: post
author: Sam Hadow
---
On my server I self-host nextcloud with a PostgreSQL database and this container image *docker.io/library/nextcloud:fpm-alpine*.
You might encounter a collation version mismatch after upgrading Nextcloud or its base image and see messages like these in your logs:
```bash
2025-11-02 18:52:12.631 UTC [3514] WARNING: database "nextcloud" has a collation version mismatch
2025-11-02 18:52:12.631 UTC [3514] DETAIL: The database was created using collation version 2.36, but the operating system provides version 2.41.
2025-11-02 18:52:12.631 UTC [3514] HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE nextcloud REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
```
This typically happens after a glibc or ICU *(in the example above the collation version changed from 236 to 2.41)*.
So with containers, it might happen when upgrading the nextcloud image.
When you create a PostgreSQL database, it stores the collation and its version (from the systems glibc or ICU). If this library is updated later, PostgreSQL warns you that the databases collation version no longer matches the system one.
This missmatch can affect:
+ Indexes on text columns
+ ORDER BY and equality comparisons (text, varchar)
## fix
You can follow this procedure to fix it:
### 1: Enable maintenance mode
The database must not be accessed during the procedure.
```bash
podman exec -u www-data nextcloud-app php occ maintenance:mode --on
```
Replace nextcloud-app with the name of your container. And use docker instead of podman if applicable.
### 2: Rebuild the database indexes and refresh the collation version
```bash
podman exec -it nextcloud-db bash
psql -U nextcloud nextcloud
REINDEX DATABASE nextcloud;
ALTER DATABASE nextcloud REFRESH COLLATION VERSION;
\q
exit
```
Log in to your nextcloud database and then reindex it, depending on the size of your nextcloud instance it might take a while, so warn your users before preferably.
The second command (`ALTER DATABASE ... REFRESH COLLATION VERSION`) just marks the collation version as current in PostgreSQL metadata and removes the warning.
### 3: Disable maintenance mode
```bash
podman exec -u www-data nextcloud-app php occ maintenance:mode --off
```
## note
I then found this [script](https://gist.github.com/troykelly/616df024050dd50744dde4a9579e152e) on github to automate this with any PostgreSQL server but didn't test it yet. Still, it's probably more convenient than doing all the steps described above manually every time.