-
Notifications
You must be signed in to change notification settings - Fork 177
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
Fix possible two vacuums concurrently processing the same relfilenode. #400
Fix possible two vacuums concurrently processing the same relfilenode. #400
Conversation
Previously, while swapping the target table and its temp table, we used to acquire an AccessExclusiveLock on only the target table but not on its temp table. So the following scenario could happen: 1. Run (auto) vacuum on the temp table. 2. Swap the target table's relfile node and the temp table's relfilenode, and commit. 3. Run (auto) vacuum on the target table. 1 and 3 run concurrently on different tables but these tables use the same relfilenode. In the reported case, since concurrent changes (INSERT/UPDATE/DELETE) can also run concurrently, the second vacuum ended up removing newly added tuples. To fix the issue, this commit changes the pg_repack command so that it acquires an AcessExclusiveLock also on the temp table before swapping these tables. Issue: reorg#399
Thanks! It looks like pg_reorg originally relied on autovacuum=off , but that's really not enough (anti-wraparound autovacuum can still start). Explicit blocking is much more correct. |
Thank you for looking at the fix. I guess we might want to check in |
sounds like good check. Although for now it should be conditional |
Thank you for the PR! Would it make sense to assign Line 902 in f5aa388
Indeed, it might be a good addition. I think instead |
Thank you for reviewing the change! I've pushed the changes. I use |
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 for the fix! Looks good to me.
Thank you for reviewing the change! I've merged it. |
Previously, while swapping the target table and its temp table, we used to acquire an AccessExclusiveLock on only the target table but not on its temp table. So the following scenario could happen:
1 and 3 run concurrently on different tables but these tables use the same relfilenode. In the reported case, since concurrent changes (INSERT/UPDATE/DELETE) can also run concurrently, the second vacuum ended up removing newly added tuples.
To fix the issue, this commit changes the pg_repack command so that it acquires an AcessExclusiveLock also on the temp table before swapping these tables.
Issue: #399