forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit20b6552
committed
Fix freezing of a dead HOT-updated tuple
Vacuum calls page-level HOT prune to remove dead HOT tuples before doingliveness checks (HeapTupleSatisfiesVacuum) on the remaining tuples. Butconcurrent transaction commit/abort may turn DEAD some of the HOT tuplesthat survived the prune, before HeapTupleSatisfiesVacuum tests them.This happens to activate the code that decides to freeze the tuple ...which resuscitates it, duplicating data.(This is especially bad if there's any unique constraints, because thoseare now internally violated due to the duplicate entries, though youwon't know until you try to REINDEX or dump/restore the table.)One possible fix would be to simply skip doing anything to the tuple,and hope that the next HOT prune would remove it. But there is aproblem: if the tuple is older than freeze horizon, this would leave anunfrozen XID behind, and if no HOT prune happens to clean it up beforethe containing pg_clog segment is truncated away, it'd later cause anerror when the XID is looked up.Fix the problem by having the tuple freezing routines cope with thesituation: don't freeze the tuple (and keep it dead). In the cases thatthe XID is older than the freeze age, set the HEAP_XMAX_COMMITTED flagso that there is no need to look up the XID in pg_clog later on.An isolation test is included, authored by Michael Paquier, looselybased on Daniel Wood's original reproducer. It only tests oneparticular scenario, though, not all the possible ways for this problemto surface; it be good to have a more reliable way to test this morefully, but it'd require more work.In messagehttps://postgr.es/m/20170911140103.5akxptyrwgpc25bw@alvherre.pgsqlI outlined another test case (more closely matching Dan Wood's) thatexposed a few more ways for the problem to occur.Backpatch all the way back to 9.3, where this problem was introduced bymultixact juggling. In branches 9.3 and 9.4, this includes a backpatchof commit e5ff9fefcd50 (of 9.5 era), since the original is notcorrectable without matching the coding pattern in 9.5 up.Reported-by: Daniel WoodDiagnosed-by: Daniel WoodReviewed-by: Yi Wen Wong, Michaël PaquierDiscussion:https://postgr.es/m/E5711E62-8FDF-4DCA-A888-C200BF6B5742@amazon.com1 parent66fd86a commit20b6552
File tree
5 files changed
+179
-27
lines changed- src
- backend
- access/heap
- commands
- test/isolation
- expected
- specs
5 files changed
+179
-27
lines changedLines changed: 40 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6405 | 6405 |
| |
6406 | 6406 |
| |
6407 | 6407 |
| |
6408 |
| - | |
6409 |
| - | |
| 6408 | + | |
| 6409 | + | |
| 6410 | + | |
| 6411 | + | |
| 6412 | + | |
| 6413 | + | |
| 6414 | + | |
6410 | 6415 |
| |
6411 | 6416 |
| |
6412 | 6417 |
| |
6413 |
| - | |
6414 |
| - | |
6415 |
| - | |
| 6418 | + | |
| 6419 | + | |
| 6420 | + | |
| 6421 | + | |
| 6422 | + | |
| 6423 | + | |
| 6424 | + | |
6416 | 6425 |
| |
6417 | 6426 |
| |
6418 | 6427 |
| |
| |||
6485 | 6494 |
| |
6486 | 6495 |
| |
6487 | 6496 |
| |
6488 |
| - | |
6489 |
| - | |
6490 |
| - | |
6491 | 6497 |
| |
6492 | 6498 |
| |
6493 | 6499 |
| |
6494 | 6500 |
| |
| 6501 | + | |
| 6502 | + | |
| 6503 | + | |
| 6504 | + | |
| 6505 | + | |
| 6506 | + | |
6495 | 6507 |
| |
6496 | 6508 |
| |
6497 | 6509 |
| |
| |||
6516 | 6528 |
| |
6517 | 6529 |
| |
6518 | 6530 |
| |
6519 |
| - | |
6520 |
| - | |
6521 |
| - | |
6522 |
| - | |
6523 |
| - | |
6524 |
| - | |
6525 |
| - | |
6526 | 6531 |
| |
6527 | 6532 |
| |
6528 | 6533 |
| |
| |||
6601 | 6606 |
| |
6602 | 6607 |
| |
6603 | 6608 |
| |
6604 |
| - | |
| 6609 | + | |
| 6610 | + | |
| 6611 | + | |
| 6612 | + | |
6605 | 6613 |
| |
6606 | 6614 |
| |
6607 | 6615 |
| |
| |||
6712 | 6720 |
| |
6713 | 6721 |
| |
6714 | 6722 |
| |
6715 |
| - | |
| 6723 | + | |
| 6724 | + | |
| 6725 | + | |
| 6726 | + | |
| 6727 | + | |
| 6728 | + | |
| 6729 | + | |
| 6730 | + | |
| 6731 | + | |
| 6732 | + | |
| 6733 | + | |
| 6734 | + | |
| 6735 | + | |
| 6736 | + | |
| 6737 | + | |
| 6738 | + | |
6716 | 6739 |
| |
6717 | 6740 |
| |
6718 | 6741 |
| |
|
Lines changed: 10 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2018 | 2018 |
| |
2019 | 2019 |
| |
2020 | 2020 |
| |
2021 |
| - | |
2022 |
| - | |
2023 |
| - | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
2024 | 2024 |
| |
2025 |
| - | |
2026 |
| - | |
2027 |
| - | |
2028 |
| - | |
2029 |
| - | |
2030 |
| - | |
2031 |
| - | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
2032 | 2032 |
| |
2033 | 2033 |
| |
2034 | 2034 |
| |
|
Lines changed: 101 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + |
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
44 | 44 |
| |
45 | 45 |
| |
46 | 46 |
| |
| 47 | + | |
47 | 48 |
| |
48 | 49 |
| |
49 | 50 |
| |
|
Lines changed: 27 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + |
0 commit comments
Comments
(0)