After the last Linux distribution upgrade, my self-hosted GitLab often displayed the following warning:
WARNING: database "gitlabhq_production" has a collation version mismatch
DETAIL: The database was created using collation version 2.35, but the operating system provides version 2.39.
HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE gitlabhq_production REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
I found the relevant commands to fix this collation version mismatch in the GitLab documentation, but it was spread across different places so I decided to write a summary of all required commands. Note that this will re-index the complete database, which might take some time. If you require a shorter downtime, alternative methods are available in the GitLab documentation.
sudo gitlab-ctl stop
sudo gitlab-ctl start postgresql
sudo gitlab-psql
SET statement_timeout = 0;
REINDEX DATABASE gitlabhq_production;
ALTER DATABASE gitlabhq_production REFRESH COLLATION VERSION;
\q
sudo gitlab-ctl start