KMail - Fix postgres db cluster upgrade failed error

After a recent update on Calculate Linux (Gentoo-based), KMail stopped launching and running it from the terminal showed the following error as the root cause of failure:

Postgres db cluster upgrade failed, Akonadi will fail to start. Sorry.

The update process had bumped up PostgreSQL from version 16 to 17, and that’s where the problem lied. Fixing this with all the KMail data intact turned out to be a relatively simpler task.

For me, the update had removed PostgreSQL version 16, and the data migration process requires both major versions (16 and 17 in this case) to be present on the system, so the first thing to do was to install PostgreSQL 16,

emerge -a1 =dev-db/postgresql-16.5

After installation was completed, the next step was to make sure that Akonadi was not running,

akonadictl stop

Before starting the data migration process, I backed up the current KMail database,

cp -R $HOME/.local/share/akonadi/db_data/ $HOME/.local/share/akonadi/db_data_16
mv $HOME/.local/share/akonadi/db_data/ $HOME/.local/share/akonadi/db_data_old

Then it was time to create a new database using the latest version of PostgreSQL (17 in this case),

/usr/lib64/postgresql-17/bin/initdb --pgdata=$HOME/.local/share/akonadi/db_data --encoding=UTF-8

Before starting the actual upgrade, I made sure that the upgrade was safe to carry out,

/usr/lib64/postgresql-17/bin/pg_upgrade -b /usr/lib64/postgresql-16/bin -B /usr/lib64//postgresql-17/bin -d $HOME/.local/share/akonadi/db_data_old/ -D $HOME/.local/share/akonadi/db_data --check

PostgreSQL didn’t complain and gave me an all-green signal, so, I went ahead with the database upgrade,

/usr/lib64/postgresql-17/bin/pg_upgrade -b /usr/lib64/postgresql-16/bin -B /usr/lib64//postgresql-17/bin -d $HOME/.local/share/akonadi/db_data_old/ -D $HOME/.local/share/akonadi/db_data

Finally, it was time to restart Akonadi services,

akonadictl start &
akonadictl fsck &

Some house cleaning,

rm -rf $HOME/.local/share/akonadi/db_data_16
rm -rf $HOME/.local/share/akonadi/db_data_old

And, Voilà! KMail was up and running again!
One thing I’d like to mention at the end is that all the commands above should be run as a regular user and not as root or with sudo. Hopefully, someone with a similar issue will find this post useful. They might have to slightly adjust a couple of things here and there, but it shouldn’t be too difficult. Fingers crossed!

A quilted piece depicting migrating elephants

Image courtesy judy_and_ed

 Date: November 26, 2024
 Tags:  how-to linux
 Comments: 

I don't have comments on this blog as they not only are difficult to manage, but are also prone to privacy and security risks.
Instead of leaving a comment, you could email me directly.

 Support: 

Liked what you just read? Please consider buying me a cup of coffee!

Previous:
⏪ ALT Linux - How to replace PulseAudio with PipeWire