Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch PostgreSQL container to use pgautoupgrade #4892

Merged
merged 5 commits into from
Jul 17, 2024

Conversation

Daniel15
Copy link
Contributor

@Daniel15 Daniel15 commented Jul 7, 2024

Lemmy changed from PostgreSQL 15 to 16 at some point, and trying to switch from 15 to 16 in docker-compose.yml results in errors like this at startup:

DETAIL: The data directory was initialized by PostgreSQL version 15, which is not compatible with this version 16.3

This PR changes the PostgreSQL container to use pgautoupgrade. The pgautoupgrade image is based on the regular PostgreSQL one, but it automatically updates the data to the newer format on startup. This avoids users having to figure it out manually.

This handles automatically upgrading the data files to newer versions of PostgreSQL.
@dessalines
Copy link
Member

Thx! I had no idea this existed, and I love it.

@Nutomic
Copy link
Member

Nutomic commented Jul 8, 2024

Looks good, please change the one in docker/federation/docker-compose.yml as well. Maybe scripts/postgres_12_to_15_upgrade.sh needs to be adjusted too as it references the image name.

@ticoombs
Copy link
Contributor

ticoombs commented Jul 9, 2024

scripts/postgres_12_to_15_upgrade.sh would be completely redundant after this change fyi.

@Daniel15
Copy link
Contributor Author

Daniel15 commented Jul 9, 2024

I'll make the requested changes soon.

@justinclift
Copy link

As a data point, we've added Debian based pgautoupgrade images now too (15-bookworm and 16-bookworm).

If your existing PostgreSQL docker image is Debian based, then it's best to use a Debian based pgautoupgrade image.

That's because we've had reports of collation problems when people upgraded their Debian based PostgreSQL image using our original (Alpine based) images. These new images should fix that. 😄

@justinclift
Copy link

Heh, and now I've looked at the actual PR (a simple 1-liner), and it's alpine based anyway. You should be good to go. 😄

@dessalines
Copy link
Member

I've fixed the other cases now.

@Daniel15
Copy link
Contributor Author

I've fixed the other cases now.

Thanks. Sorry I didn't get to it - I've been busy with other things.

@dessalines
Copy link
Member

No probs.

Copy link
Contributor

@ticoombs ticoombs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving under the condition we have tested in CI and its passing. (Oh, wrong repo, but reviewed anyway!)

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @ticoombs mentioned, these migration scripts arent needed anymore. However they are still linked in Lemmy release announcements, so I would leave them in but remove everything except for this line:
sudo sed -i "s/image: .*postgres:.*/image: pgautoupgrade\/pgautoupgrade:16-alpine/" ./docker-compose.yml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Nutomic Nutomic merged commit 8abbd56 into LemmyNet:main Jul 17, 2024
1 check passed
Nutomic pushed a commit to sunaurus/lemmy that referenced this pull request Sep 20, 2024
* Switch PostgreSQL container to use pgautoupgrade

This handles automatically upgrading the data files to newer versions of PostgreSQL.

* Fixing other uses of postgres:16-alpine image.

* Simplifying upgrade scripts.

---------

Co-authored-by: Dessalines <[email protected]>
@Daniel15 Daniel15 deleted the patch-1 branch November 10, 2024 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants