Migrate Gitea/Forgejo from MariaDB/MySQL to PostgreSQL

<1 min read

I spent most of last night trying to figure out how to migrate my Forgejo (Gitea) database from MariaDB (MySQL) to PostgreSQL. There's a lot of misleading information out there, so I figured I'd post about it and hopefully prevent someone for falling into a rabbit hole like I did.

First, a bit about my setup. I'm using MariaDB and Forgejo, but these steps will work with MySQL and Gitea too. My database name is forgejodb (which will most likely be giteadb when using Gitea).

To migrate, the steps are:

  • Dump the current Forgejo database using:
forgejo dump --database postgres --config /etc/forgejo/app.ini
  • Unzip the dump archive:
mkdir tmp
cd tmp
unzip ../forgejo-dump-XXXXXXXXXX.zip
  • Create the user and database in PostgreSQL;
sudo -u postgres psql
postgres=# CREATE USER forgejo WITH PASSWORD 'changeme';
postgres=# CREATE DATABASE forgejo WITH OWNER forgejo TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
  • Import the dump data into PostgreSQL:
psql --username forgejo -h localhost --set ON_ERROR_STOP=on forgejodb < forgejo-db.sql

Don't forget to edit your app.ini with:

DB_TYPE = postgres
HOST = 127.0.0.1:5432

It's pretty straightforward if you have the right steps.