From a05782753afef57d39e0766398286c118ab681a9 Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Sun, 7 Jul 2024 15:12:36 -0700 Subject: [PATCH 1/3] Switch PostgreSQL container to use pgautoupgrade This handles automatically upgrading the data files to newer versions of PostgreSQL. --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 655182e1aa..c1d8d359b9 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -97,7 +97,7 @@ services: logging: *default-logging postgres: - image: postgres:16-alpine + image: pgautoupgrade/pgautoupgrade:16-alpine # this needs to match the database host in lemmy.hson # Tune your settings via # https://pgtune.leopard.in.ua/#/ From 6bba6b1767501f5d225766de8e63ae5b0d6fd3b5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 15 Jul 2024 12:51:32 -0400 Subject: [PATCH 2/3] Fixing other uses of postgres:16-alpine image. --- .woodpecker.yml | 2 +- docker/federation/docker-compose.yml | 2 +- scripts/postgres_12_to_15_upgrade.sh | 2 +- scripts/postgres_15_to_16_upgrade.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index b77fd6615d..fe11411d86 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -306,7 +306,7 @@ steps: services: database: - image: postgres:16-alpine + image: pgautoupgrade/pgautoupgrade:16-alpine environment: POSTGRES_USER: lemmy POSTGRES_PASSWORD: password diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index 72a8145ecf..2befc78c52 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:16-alpine + image: pgautoupgrade/pgautoupgrade:16-alpine environment: - POSTGRES_USER=lemmy - POSTGRES_PASSWORD=password diff --git a/scripts/postgres_12_to_15_upgrade.sh b/scripts/postgres_12_to_15_upgrade.sh index 0850e8fca7..4c9fe7ee1d 100755 --- a/scripts/postgres_12_to_15_upgrade.sh +++ b/scripts/postgres_12_to_15_upgrade.sh @@ -22,7 +22,7 @@ echo "Removing the old postgres folder" sudo rm -rf volumes/postgres echo "Updating docker-compose to use postgres version 15." -sed -i "s/image: postgres:.*/image: postgres:15-alpine/" ./docker-compose.yml +sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:15-alpine/" ./docker-compose.yml echo "Starting up new postgres..." sudo docker-compose up -d postgres diff --git a/scripts/postgres_15_to_16_upgrade.sh b/scripts/postgres_15_to_16_upgrade.sh index d83803a4f9..38e1806101 100755 --- a/scripts/postgres_15_to_16_upgrade.sh +++ b/scripts/postgres_15_to_16_upgrade.sh @@ -24,7 +24,7 @@ echo "Removing the old postgres folder" sudo rm -rf volumes/postgres echo "Updating docker compose to use postgres version 16." -sudo sed -i "s/image: .*postgres:.*/image: docker.io\/postgres:16-alpine/" ./docker-compose.yml +sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:16-alpine/" ./docker-compose.yml echo "Starting up new postgres..." sudo docker compose up -d postgres From 295e351fa4c92367f2beb7994f63b50b7b1df8de Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 16 Jul 2024 12:04:29 -0400 Subject: [PATCH 3/3] Simplifying upgrade scripts. --- scripts/postgres_12_to_15_upgrade.sh | 44 ++-------------------------- scripts/postgres_15_to_16_upgrade.sh | 38 ++---------------------- 2 files changed, 4 insertions(+), 78 deletions(-) diff --git a/scripts/postgres_12_to_15_upgrade.sh b/scripts/postgres_12_to_15_upgrade.sh index 4c9fe7ee1d..9af9af64ed 100755 --- a/scripts/postgres_12_to_15_upgrade.sh +++ b/scripts/postgres_12_to_15_upgrade.sh @@ -1,48 +1,8 @@ #!/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 -sleep 20s - -echo "Exporting the Database to 12_15.dump.sql ..." -sudo docker-compose exec -T postgres pg_dumpall -c -U lemmy > 12_15_dump.sql -echo "Done." - -echo "Stopping postgres..." -sudo docker-compose stop postgres -sleep 20s - -echo "Removing the old postgres folder" -sudo rm -rf volumes/postgres - -echo "Updating docker-compose to use postgres version 15." -sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:15-alpine/" ./docker-compose.yml - -echo "Starting up new postgres..." -sudo docker-compose up -d postgres -sleep 20s - -echo "Importing the database...." -cat 12_15_dump.sql | sudo docker-compose exec -T postgres psql -U lemmy -echo "Done." - -POSTGRES_PASSWORD=$(grep "POSTGRES_PASSWORD" ./docker-compose.yml | cut -d"=" -f2) - -echo "Fixing a weird password issue with postgres 15" -sudo docker-compose exec -T postgres psql -U lemmy -c "alter user lemmy with password '$POSTGRES_PASSWORD'" -sudo docker-compose restart postgres - -echo "Setting correct perms for pictrs folder" -sudo chown -R 991:991 volumes/pictrs +echo "Updating docker-compose to use postgres version 16." +sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:16-alpine/" ./docker-compose.yml echo "Starting up lemmy..." sudo docker-compose up -d - -echo "A copy of your old database is at 12_15.dump.sql . You can delete this file if the upgrade went smoothly." -echo "Upgrade complete." diff --git a/scripts/postgres_15_to_16_upgrade.sh b/scripts/postgres_15_to_16_upgrade.sh index 38e1806101..9af9af64ed 100755 --- a/scripts/postgres_15_to_16_upgrade.sh +++ b/scripts/postgres_15_to_16_upgrade.sh @@ -1,42 +1,8 @@ #!/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 | sudo tee 15_16_dump.sql > /dev/null -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." +echo "Updating docker-compose to use postgres version 16." sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:16-alpine/" ./docker-compose.yml -echo "Starting up new postgres..." -sudo docker compose up -d postgres -echo "Waiting..." -sleep 20s - -echo "Importing the database...." -sudo 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." +sudo docker-compose up -d