-
Notifications
You must be signed in to change notification settings - Fork 22
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
Automatically do post upgrade steps (vacuum analyze, database reindexing) #50
Conversation
|
Note that I'm unsure (so far) how to properly test this. Might need to ask on an appropriate PostgreSQL developers mailing list for ideas. 😄 |
I have a couple of thoughts, already sorry for the wall of text 😅 How do we know what we need to do after an upgrade? I recently manually upgraded Postgres from v13 to v16 (application is not containerized so we also did not bother to containize Postgres) and there
I also read through https://www.crunchydata.com/blog/examining-postgres-upgrades-with-pg_upgrade and there they suggested that extensions sometimes also require their own upgrade. Reindexing seems to only necessary only in certain cases, like you mentioned here.
I would suggest we run
I know it is against the rule of Docker to have more than one "main" process in a container. I think it would be good to have the server up as soon as possible, but still run the reindex operation, therefore the suggestion with the separate process. I am wondering if we should drop
as an idea: maybe we can query PG from our |
Ugh, I totally forgot about the whole "vacuum analyse" thing afterwards. 🤦 Yeah, we'd better do that too.
😬 Well, I'm calling "edge case" on that and reckon we can look at PG extension upgrades at a later point. Lets get the fundamentals working ok first. 😄
Yeah. While we could create a big multi-dimensional matrix to track the version upgrades where it is and isn't needed... I reckon that's more an optimisation for a (maybe) later date. 😁
Heh Heh Heh, I was afraid of that. 😁 I guess we'd better do it properly rather than cheap+easy. 😉 We'll probably need to figure out a reliable way of forking a background process to do the reindexing in the background when the main database process is started. We can probably just launch some kind of bash script in the background that waits for the database to report it's available, then we run the post upgrade tasks and log the progress/errors somewhere from that.
After going through the implementation process a bit, I reckon you're right. That variable has been removed. 😄
Oh, that's a good idea. PostgreSQL also apparently has a progress counter thing for reindexes available via some system table. At least, that's what the docs mention though I've not looked at the details:
This is the Section 27.4.4 it refers to.
Nah, probably not the right approach. Large databases can take ages to reindex (even hours), especially if it's done concurrently. |
had the same thought. we can probably just something like that in the entrypoint script.
I meant a timeout of 1 minute when we test the container with |
Cool, yeah good thoughts. I'll probably have a go at adding some of those pieces over the next few days if no-one else gets to it first. That being said, if anyone else wants to try implementing bits first then please do. 😁 |
e9f1be5
to
51fe3ce
Compare
k, I think the post upgrade scripting is mostly done. Or at least to the point where it's suitable for looking over for any obvious problems. 😄 One thing it doesn't yet handle is upgrading any extensions. We'll probably want to have a look at automating that in this PR too if it seems fairly straight forward (I haven't checked). |
b138ebc
to
7ea0a4b
Compare
As a data point, I'm manually testing this on my local development computer by first manually creating a PG 16 database directory locally:
Then running the locally built
When the post upgrade script runs, its stdout and stderr output is captured into a file in the
and:
|
If anyone's interested in testing this PR on their database, I've just pushed an image (
It'd expect it to work without issue. Shouldn't be any errors or anything along those lines. In theory. 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cool stuff 😎
c4aa2f2
to
f3864d4
Compare
a569006
to
dcbed7e
Compare
It took the one shot testing a bit more effort than I was expecting, but it should be workable for now. Still need to properly look into the upgrading of extensions. Probably a tomorrow thing, as it's not something for tonight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me. thanks for adding the feature!
I suppose we can close #10 after merging this?
echo "'One shot' automatic upgrade was requested, so exiting as there is no upgrade to do" | ||
echo "If you're seeing this message and expecting an upgrade to be happening, it probably" | ||
echo "means the container is being started in a loop and a previous run already did it :)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good messages, will make it very clear to users what is happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. 😄
Uh oh. Right after merging this I've realised that hard coding the database name of
I'll test locally if using one of template databases will work instead (pretty sure it will), then I'll create a PR to fix that. |
Instead of using a template database, I've just passed through the name of the database being used by the docker entrypoint script and re-used that. Theoretically (!) it should be fine. 😁 |
This is initial code for automatically doing post upgrade tasks (vacuum analyze to refresh query planner stats, reindex the databases) after a major version upgrade.
It's passing in the initial testing I've been running locally, though I haven't tried anything too funky yet. The code itself is pretty straight forward, so it shouldn't be all that fragile. Hopefully. 😄