Saturday, February 28, 2026

PostgreSQL: collation version mismatch

Resolving "collation version mismatch" warnings after a PostgreSQL upgrade

Introduction

This article discusses the appearance and resolution of "collation version mismatch" warning messages appearing in the application logs after upgrading a PostgreSQL database.

Here is an abridged example of the warning messages seen in the logs:


WARNING: database "postgres" has a collation version mismatch
DETAIL: The database was created using collation version 2.36,
but the operating system provides version 2.41.
HINT: Rebuild all objects in this database that use the default
collation and run ALTER DATABASE postgres REFRESH COLLATION VERSION,
or build PostgreSQL with the right library version.

This is a great example of application developers providing clear and concise log messages for the end user.

According to the PostgreSQL documentation:

A change in collation definitions can lead to corrupt indexes and other problems because the database system relies on stored objects having a certain sort order. Generally, this should be avoided, but it can happen in legitimate circumstances, such as when upgrading the operating system to a new major version or when using pg_upgrade to upgrade to server binaries linked with a newer version of ICU. When this happens, all objects depending on the collation should be rebuilt, for example, using REINDEX. When that is done, the collation version can be refreshed using the command ALTER COLLATION ... REFRESH VERSION. This will update the system catalog to record the current collation version and will make the warning go away. Note that this does not actually check whether all affected objects have been rebuilt correctly.

Note: For this particular use case, I am running Django(5.2.x) web applications with a PostgreSQL(15.x) database back end within Docker(29.2.1) containers on a Debian testing(trixie) Linux distribution.

Instructions

  1. Update docker-compose.yml with new version of the PostgreSQL database.
    • For example, replace the statement image: postgres:15.11 with image: postgres:15.17.
    • See the official PostgreSQL Docker image page for additional information.
  2. Rebuild the Docker environment: docker compose up --build
  3. Once the build is finished, the warning messages mentioned above will start appearing in the logs.

  4. Make a note of all the databases listed in the log messages that need to be rebuilt. In this case, we have four databases to update:

    • test_django-start
    • template1
    • postgres
    • django-start
  5. Log into the database container:

    sh docker exec -it django_start-db bash

  6. Connect to the first database.

    psql -d test_django-start -U django_admin

  7. Execute the commands appropriate to the connected database.

    ALTER DATABASE "test_django-start" REFRESH COLLATION VERSION;

    REINDEX DATABASE "test_django-start";

    \c template1

    ALTER DATABASE template1 REFRESH COLLATION VERSION;

    REINDEX DATABASE template1;

    \c postgres

    ALTER DATABASE postgres REFRESH COLLATION VERSION;

    REINDEX DATABASE postgres;

    \c django-start

    ALTER DATABASE "django-start" REFRESH COLLATION VERSION;

    REINDEX DATABASE "django-start";

    \q # quit psql

    exit # exit container

  8. Restart the database container.

    docker stop django_start-db docker start django_start-db

Further Reading

Saturday, January 31, 2026

Managing Ruby installations using rbenv and ruby-build

Installing rbenv and ruby-build on Debian-based systems to manage Ruby versions

"rbenv is a version manager tool for the Ruby programming language on Unix-like systems. It is useful for switching between multiple Ruby versions on the same machine and for ensuring that each project you are working on always runs on the correct Ruby version." -- rbenv's README

Introduction

In this article, I will provide steps to install and configure rbenv and ruby-build on a Debian-based Linux system.

Similar to other programming languages(e.g. Python, Perl, and Rust, etc.), I prefer to keep the version of Ruby I use separate from the version installed by my system. This includes any plugins, or packages(in Ruby's case gems). Aside from giving me more granular control, it also helps prevent me from potentially breaking my system by installing an incompatible version of the language.

I've chosen to use rbenv and ruby-build to provide me with a user-controlled environment in which to manage my Ruby installations. There are several other tools(e.g. rvm and asdf that provide similar functionality. My reasoning for selecting rbenv as my tool of choice is simple. I've been using pyenv for several years to manage my Python installations. Pyenv is a direct fork of rbenv, their developers contribute upstream to rbenv and has a familiar command set. Among other features, rbenv provides support for specifying application-specific Ruby versions(via the rbenv local command).

See rbenv's README for additional details on installation and functionality.

For additional information on rbenv, managing gems, or installing Ruby on Rails, take a look a the links provided in the Further Reading section.

Installation

Installing System Prerequisites

Before installing rbenv, we need to ensure that the system has some necessary dependencies installed. From the command line, enter the following commands:


sudo apt update
sudo apt install git curl libssl-dev \
    libreadline-dev zlib1g-dev autoconf \
    bison build-essential libyaml-dev \
    libreadline-dev libncurses5-dev \
    libffi-dev libgdbm-dev libsqlite3-dev

Depending on your system, you may already have some of these packages installed, or you may need to install additional dependencies. The output from sudo apt install should provide additional guidance. system.

Installing rbenv

  1. Clone rbenv into ~/.rbenv.
    • git clone https://github.com/rbenv/rbenv.git ~/.rbenv
  2. Configure your shell to load rbenv when starting the terminal:
    • echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    • echo 'eval"$(rbenv init - bash)"' >> ~/.bashrc
  3. Reload your shell configuration for changes to take effect. source ~/.bashrc

NOTE: If you are using a shell other than bash, replace ~/.bashrc in the above commands with the appropriate filename(e.g. ~/.zshrc or ~/.config/fish/config.fish)

Installing ruby-build

ruby-build will need to be installed to help compile Ruby binaries. Run the following commands to create a directory for the ruby-build plugin and then download it to the proper directory:


mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Verifying installation

  1. Check installed version of rbenv

~$rbenv -v (or --version)
rbenv 1.3.2-16-gba96d7e

To check which version of Ruby is installed, use rbenv version(no dashes).

  1. Run rbenv-doctor

The rbenv-doctor script analyzes your system setup for common problems. Run this script to verify that the installation was successful.

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash

or

wget -q https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor -O- | bash

Either of the commands should produce output similar to the following:


Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: ~/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20260121)
Counting installed Ruby versions: 1 versions
Auditing installed plugins: OK

For additional troubleshooting assistance, refer to the rbenv wiki

Installing Ruby

With rbenv installed, an updated list of the available Ruby versions can be viewed with the command:


rbenv install -l

#Output

3.2.10
3.3.10
3.4.8
4.0.1
jruby-10.0.2.0
mruby-3.4.0
picoruby-3.0.0
truffleruby-33.0.1
truffleruby+graalvm-33.0.1

Only latest stable releases for each Ruby implementation are shown. Use `rbenv install --list-all' to show all local versions.

As of this writing(20260128), the latest version of Ruby is 4.0.1.


    rbenv install 4.0.1 --verbose

This command should take roughly fifteen minutes to complete. Using the --verbose flag will produce output to the console so that the installation progress can be observed.

Set Default Ruby Version

Once Ruby is installed, set the default version using the global option:


rbenv global 4.0.1

Next, verify that Ruby was properly installed by checking its version number:


ruby --version

#Output

ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux]

To install and use a different version of Ruby, run the rbenv commands with a different version number, such as rbenv install 3.4.8 and rbenv global 3.4.8.

Removing unneeded Ruby versions

The rbenv uninstall command can be used to remove old versions of Ruby that are no longer needed.


rbenv uninstall 4.0.1

Updating rbenv and ruby-build

Updating rbenv


cd ~/.rbenv
git pull

Updating ruby-build


cd ~/.rbenv
git -C plugins/ruby-build pull

Further Reading

rbenv alternatives