Re: BUG #16785: Postgresql shutdown during initial pg_prewarm prewarming causes Pg to get stuck
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jthompson@maxmind.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2020-12-22T01:10:59Z
Lists: pgsql-bugs
Attachments
- teach-autoprewarm-about-early-shutdown-1.patch (text/x-diff) patch
PG Bug reporting form <noreply@postgresql.org> writes: > We use pg_prewarm via shared_preload_libraries and we've noticed that if we > start Pg then stop it again before pg_prewarm finishes its initial > prewarming, Pg gets stuck in shutdown until we kill the 'autoprewarm master' > process with 'kill -9'. Yeah. I assume you've got multiple large databases? When I try this here, the current autoprewarm worker process shuts down promptly, but then the master process tries to launch another worker for the next DB, and then just sits there because the postmaster is now ignoring worker start requests. So this is partly autoprewarm's fault, because it's taking no thought for the possibility that a shutdown will be requested before it's managed to preload everything. But it's *mostly* the fault of the incredibly brain-dead design for background workers, which has no way to tell worker requestors that their request is never going to be granted. I've ranted about that before, with little effect on the people responsible, so I guess at some point I'm going to have to go fix it myself. In the meantime, attached is a proposed patch that improves autoprewarm's behavior. It will only get stuck if you're unlucky enough to issue "pg_ctl stop" just as it's trying to launch another worker, which should be a pretty tight window. I noticed while testing this that when autoprewarm did get out of the situation promptly, it'd rewrite autoprewarm.blocks with only as many blocks as it'd managed to prewarm before being canceled. This doesn't seem like a good thing, because then the next start might have next door to no prewarm behavior. So the patch also hacks it to skip the final autoprewarm.blocks dump if we were told to terminate before the initial prewarming pass is done. This is against HEAD but it seems to apply cleanly to v12. If you're in a position to rebuild pg_prewarm with the patch, please see if it resolves the problem for you. regards, tom lane
Commits
-
Improve autoprewarm's handling of early-shutdown scenarios.
- ff769831e081 14.0 landed
- f581e5383648 12.6 landed
- a1bd14d54e52 11.11 landed
- 4b0292253cfc 13.2 landed