From 9367cbdb009c9a2a1658ceeb74ceec20fccaf6bc Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 7 Feb 2024 05:21:02 -0500 Subject: [PATCH] Upgrading from postgres 15 -> 16-alpine. (#4426) - Includes an upgrade script. - Fixes #4406 --- .woodpecker.yml | 2 +- docker/docker-compose.yml | 2 +- docker/federation/docker-compose.yml | 2 +- scripts/postgres_15_to_16_upgrade.sh | 42 ++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100755 scripts/postgres_15_to_16_upgrade.sh diff --git a/.woodpecker.yml b/.woodpecker.yml index 409f962d1..a51a1499d 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -257,7 +257,7 @@ steps: services: database: - image: postgres:15.2-alpine + image: postgres:16-alpine environment: POSTGRES_USER: lemmy POSTGRES_PASSWORD: password diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7b22c2420..30b38ad85 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -99,7 +99,7 @@ services: logging: *default-logging postgres: - image: postgres:15-alpine + image: postgres:16-alpine # this needs to match the database host in lemmy.hson # Tune your settings via # https://pgtune.leopard.in.ua/#/ diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index 814d43119..8dd70f3bc 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -20,7 +20,7 @@ x-lemmy-default: &lemmy-default restart: always x-postgres-default: &postgres-default - image: postgres:15-alpine + image: postgres:16-alpine environment: - POSTGRES_USER=lemmy - POSTGRES_PASSWORD=password diff --git a/scripts/postgres_15_to_16_upgrade.sh b/scripts/postgres_15_to_16_upgrade.sh new file mode 100755 index 000000000..20a6c594c --- /dev/null +++ b/scripts/postgres_15_to_16_upgrade.sh @@ -0,0 +1,42 @@ +#!/bin/sh +set -e + +echo "Do not stop in the middle of this upgrade, wait until you see the message: Upgrade complete." + +echo "Stopping lemmy and all services..." +sudo docker-compose stop + +echo "Make sure postgres is started..." +sudo docker-compose up -d postgres +echo "Waiting..." +sleep 20s + +echo "Exporting the Database to 15_16.dump.sql ..." +sudo docker-compose exec -T postgres pg_dumpall -c -U lemmy > 15_16_dump.sql +echo "Done." + +echo "Stopping postgres..." +sudo docker-compose stop postgres +echo "Waiting..." +sleep 20s + +echo "Removing the old postgres folder" +sudo rm -rf volumes/postgres + +echo "Updating docker-compose to use postgres version 16." +sed -i "s/image: postgres:.*/image: postgres:16-alpine/" ./docker-compose.yml + +echo "Starting up new postgres..." +sudo docker-compose up -d postgres +echo "Waiting..." +sleep 20s + +echo "Importing the database...." +cat 15_16_dump.sql | sudo docker-compose exec -T postgres psql -U lemmy +echo "Done." + +echo "Starting up lemmy..." +sudo docker-compose up -d + +echo "A copy of your old database is at 15_16.dump.sql . You can delete this file if the upgrade went smoothly." +echo "Upgrade complete."