Skip to content

Bringing Kmail and PostgreSQL together

Kmail, the mail program of the KDE project, does not come alone. Also included is an address book, an appointment manager, a notification service and much more. The whole thing is kept running by Akonadi, the backend of the whole KDE PIM Suite.

By default Akonadi runs with MySQL as database system, but this has caused quite some fuss again and again. So I looked around for alternatives and ended up at PostgreSQL next to SQLite. Unfortunately there were some negative reports about SQLite and the implementation in Akonadi, so I sorted it out directly.
I had no experience with PostgreSQL, but was able to set it up quite quickly. Connecting Akonadi and Kmail to PostgreSQL was also easy.

All steps under openSUSE

First we install all necessary packages for PostgreSQL and the Akonadi connection:

# zypper in postgresql-server libQt5Sql5-postgresql

Activate and start PostgreSQL Server:

# systemctl enable --now postgresql

Create Postgres user and database:

# su - postgres
$ createuser <your-username>
$ psql postgres
postgres=# alter user <your-username> createdb;
postgres=# \q;
# exit

Then we set up the database access with your regular user account:

$ createdb akonadi-<your-username>

Now we stop Akonadi and delete or move the settings. This is especially important if you have already had started Akonadi!

$ akonadictl stop
$ rm -rf ~/.local/share/akonadi

We adjust the connection to the database server in the file ~/.config/akonadi/akonadiserverrc as follows:

[%General]
Driver=QPSQL

[QPSQL]
Host=/tmp/akonadi-<your-username>.hash
InitDbPath=/usr/bin/initdb
Name=akonadi
Options=
ServerPath=/usr/bin/pg_ctl
StartServer=true

Finally restart Akonadi and you are ready to go:

$ akonadictl start