The easiest path for migrating Forgejo to PostgreSQL seems to be with the forgejo dump
command. However, the import into the PostgreSQL database failed with
ERROR: stack depth limit exceeded
I then tried to import the data and structure into an empty PostgreSQL database with pgloader. Forgejo rejected to start after the the import due to an unexpected database schema.
In the end I started Forgejo with an empty PostgreSQL database and waited until all tables were set up and then stopped the Forgejo process again. To not mess with the production data, I first copied the sqlite file. I then configured pgloader to only import the data. The pgloader config:
LOAD DATABASE
FROM sqlite:///root/forgejo.db
INTO postgresql://forgejo:SECRET@127.0.0.1/forgejo
WITH data only, reset sequences, prefetch rows = 10000
SET work_mem TO '16MB', maintenance_work_mem TO '512MB';
There were still some problems with columns that did exist in the SQLite database but not in the PostgreSQL database. I simply removed those columns in the copy of the SQLite database:
ALTER TABLE session DROP COLUMN created_unix;
ALTER TABLE hook_task DROP COLUMN repo_id;
Additionally, the keep_activity_private
column did have some NULL values in the SQLite database. I solved this by first allowing NULL values in the PSQL database, then updating all values, and then again disallowing NULL values:
ALTER TABLE public.user ALTER COLUMN keep_activity_private DROP NOT NULL;
# run pgloader now
UPDATE public.user SET keep_activity_private=TRUE WHERE keep_activity_private IS NULL;
ALTER TABLE public.user ALTER COLUMN keep_activity_private SET NOT NULL;
In the end I can definitely recommend the migration. Forgejo is much faster with PSQL.