Solved: Upgrading Mastodon from 4.2.x to 4.3.1


It’s been almost 4 years since I started my own Mastodon instance. I took a look at the latest releases and my instance is way behind, so I decided to give v4.3.1 a try.

With all the YAMLs and Kustomize stuff I did before, last few upgrades were as simple as a version number change. I guess there are more improvements in 4.3 so after I pushed my commit there were errors emerging.

The first error is from the DB migration job:

Mastodon now requires that these variables are set:

  - ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY
  - ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT
  - ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY

Run `bin/rails db:encryption:init` to generate new secrets and then assign the environment variables.
Exiting

The suggestion is already there so there’s no need to google it even. I then ran the suggested command to generate the 3 new environment variables for my instance, using a docker container.

docker run --rm -ti ghcr.io/mastodon/mastodon:v4.3.1 bash
mastodon@21c571261e3e:~$ pwd
/opt/mastodon
mastodon@21c571261e3e:~$ bin/rails db:encryption:init
Add the following secret environment variables to your Mastodon environment (e.g. .env.production), ensure they are shared across all your nodes and do not change them after they are set:

ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=[REDACTED]
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=[REDACTED]
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=[REDACTED]

Looks like I need to keep these really safe so I kept a backup of these after I added them to my Mastodon instance. I tried the DB migration job again and it failed again… Only the error this time is different so this is good progress.

... permission denied for schema public

This is probably caused by my recent PostgreSQL upgrade, from 14 to 16. All I need to do is to grant ownership again to the mastodon user.

# SSH to PostgreSQL server
su postgres
postgres@server:/root$ psql
psql (16.4 (Ubuntu 16.4-0ubuntu0.24.04.2))
Type "help" for help.
postgres=# ALTER DATABASE mastodon OWNER to mastodon;
ALTER DATABASE

Then I ran the DB migration job again and it passed!

Is that it? Still an error coming out from the streaming service:

OCI runtime create failed: runc create failed: unable to start container process: exec: "node": executable file not found in $PATH

I had no idea what this means so Google found this issue for me. The fix is easy, instead of using ghcr.io/mastodon/mastodon:v4.3.1 for the streaming pod, a new dedicated image ghcr.io/mastodon/mastodon-streaming:v4.3.1 should be used instead.

And that’s it, my Mastodon is now upgraded to the latest release. 🙂