forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit0350b87
committed
Fix corruption when relation truncation fails.
RelationTruncate() does three things, while holding anAccessExclusiveLock and preventing checkpoints:1. Logs the truncation.2. Drops buffers, even if they're dirty.3. Truncates some number of files.Step 2 could previously be canceled if it had to wait for I/O, and step3 could and still can fail in file APIs. All orderings of theseoperations have data corruption hazards if interrupted, so we can't giveup until the whole operation is done. When dirty pages were discardedbut the corresponding blocks were left on disk due to ERROR, old pageversions could come back from disk, reviving deleted data (seepgsql-bugs #18146 and several like it). When primary and standby wereallowed to disagree on relation size, standbys could panic (seepgsql-bugs #18426) or revive data unknown to visibility management onthe primary (theorized).Changes: * WAL is now unconditionally flushed first * smgrtruncate() is now called in a critical section, preventing interrupts and causing PANIC on file API failure * smgrtruncate() has a new parameter for existing fork sizes, because it can't call smgrnblocks() itself inside a critical sectionThe changes apply to RelationTruncate(), smgr_redo() andpg_truncate_visibility_map(). That last is also brought up to date withother evolutions of the truncation protocol.The VACUUM FileTruncate() failure mode had been discussed in olderreports than the ones referenced below, with independent analysis frommany people, but earlier theories on how to fix it were too complicatedto back-patch. The more recently invented cancellation bug wasdiagnosed by Alexander Lakhin. Other corruption scenarios were spottedby me while iterating on this patch and earlier commit75818b3.Back-patch to all supported releases.Reviewed-by: Michael Paquier <michael@paquier.xyz>Reviewed-by: Robert Haas <robertmhaas@gmail.com>Reported-by: rootcause000@gmail.comReported-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://postgr.es/m/18146-04e908c662113ad5%40postgresql.orgDiscussion:https://postgr.es/m/18426-2d18da6586f152d6%40postgresql.org1 parent9e85b20 commit0350b87
6 files changed
+88
-33
lines changedLines changed: 22 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
380 | 380 |
| |
381 | 381 |
| |
382 | 382 |
| |
| 383 | + | |
383 | 384 |
| |
384 | 385 |
| |
385 | 386 |
| |
| |||
389 | 390 |
| |
390 | 391 |
| |
391 | 392 |
| |
| 393 | + | |
| 394 | + | |
392 | 395 |
| |
393 |
| - | |
394 |
| - | |
395 |
| - | |
396 |
| - | |
397 |
| - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
398 | 405 |
| |
399 | 406 |
| |
400 | 407 |
| |
| 408 | + | |
401 | 409 |
| |
402 | 410 |
| |
403 | 411 |
| |
| |||
407 | 415 |
| |
408 | 416 |
| |
409 | 417 |
| |
410 |
| - | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
411 | 421 |
| |
412 | 422 |
| |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
413 | 429 |
| |
414 | 430 |
| |
415 | 431 |
| |
|
Lines changed: 32 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
291 | 291 |
| |
292 | 292 |
| |
293 | 293 |
| |
| 294 | + | |
294 | 295 |
| |
295 | 296 |
| |
296 | 297 |
| |
| |||
306 | 307 |
| |
307 | 308 |
| |
308 | 309 |
| |
| 310 | + | |
309 | 311 |
| |
310 | 312 |
| |
311 | 313 |
| |
| |||
317 | 319 |
| |
318 | 320 |
| |
319 | 321 |
| |
| 322 | + | |
320 | 323 |
| |
321 | 324 |
| |
322 | 325 |
| |
| |||
330 | 333 |
| |
331 | 334 |
| |
332 | 335 |
| |
| 336 | + | |
333 | 337 |
| |
334 | 338 |
| |
335 | 339 |
| |
| |||
366 | 370 |
| |
367 | 371 |
| |
368 | 372 |
| |
369 |
| - | |
370 |
| - | |
371 |
| - | |
372 |
| - | |
373 |
| - | |
374 |
| - | |
375 |
| - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
376 | 384 |
| |
| 385 | + | |
| 386 | + | |
377 | 387 |
| |
378 | 388 |
| |
379 | 389 |
| |
| |||
397 | 407 |
| |
398 | 408 |
| |
399 | 409 |
| |
400 |
| - | |
| 410 | + | |
| 411 | + | |
401 | 412 |
| |
402 |
| - | |
403 |
| - | |
| 413 | + | |
404 | 414 |
| |
405 | 415 |
| |
406 | 416 |
| |
407 | 417 |
| |
408 | 418 |
| |
409 | 419 |
| |
410 | 420 |
| |
411 |
| - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
412 | 424 |
| |
413 | 425 |
| |
414 | 426 |
| |
| |||
973 | 985 |
| |
974 | 986 |
| |
975 | 987 |
| |
| 988 | + | |
976 | 989 |
| |
977 | 990 |
| |
978 | 991 |
| |
| |||
1007 | 1020 |
| |
1008 | 1021 |
| |
1009 | 1022 |
| |
| 1023 | + | |
1010 | 1024 |
| |
1011 | 1025 |
| |
1012 | 1026 |
| |
| |||
1024 | 1038 |
| |
1025 | 1039 |
| |
1026 | 1040 |
| |
| 1041 | + | |
1027 | 1042 |
| |
1028 | 1043 |
| |
1029 | 1044 |
| |
| |||
1035 | 1050 |
| |
1036 | 1051 |
| |
1037 | 1052 |
| |
| 1053 | + | |
1038 | 1054 |
| |
1039 | 1055 |
| |
1040 | 1056 |
| |
1041 | 1057 |
| |
1042 | 1058 |
| |
1043 | 1059 |
| |
1044 |
| - | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
1045 | 1065 |
| |
1046 | 1066 |
| |
1047 | 1067 |
| |
|
Lines changed: 20 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1141 | 1141 |
| |
1142 | 1142 |
| |
1143 | 1143 |
| |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
1144 | 1151 |
| |
1145 | 1152 |
| |
1146 |
| - | |
| 1153 | + | |
| 1154 | + | |
1147 | 1155 |
| |
1148 |
| - | |
1149 | 1156 |
| |
1150 | 1157 |
| |
1151 | 1158 |
| |
1152 |
| - | |
1153 |
| - | |
1154 |
| - | |
1155 |
| - | |
1156 |
| - | |
1157 | 1159 |
| |
1158 | 1160 |
| |
1159 | 1161 |
| |
| |||
1492 | 1494 |
| |
1493 | 1495 |
| |
1494 | 1496 |
| |
1495 |
| - | |
| 1497 | + | |
1496 | 1498 |
| |
1497 | 1499 |
| |
1498 | 1500 |
| |
| |||
1504 | 1506 |
| |
1505 | 1507 |
| |
1506 | 1508 |
| |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
1507 | 1519 |
| |
1508 | 1520 |
| |
1509 | 1521 |
| |
|
Lines changed: 10 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
102 |
| - | |
| 102 | + | |
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| |||
697 | 697 |
| |
698 | 698 |
| |
699 | 699 |
| |
700 |
| - | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
701 | 705 |
| |
702 | 706 |
| |
703 |
| - | |
| 707 | + | |
| 708 | + | |
704 | 709 |
| |
705 | 710 |
| |
706 | 711 |
| |
| |||
728 | 733 |
| |
729 | 734 |
| |
730 | 735 |
| |
731 |
| - | |
| 736 | + | |
| 737 | + | |
732 | 738 |
| |
733 | 739 |
| |
734 | 740 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
44 |
| - | |
| 44 | + | |
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
106 |
| - | |
107 |
| - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
108 | 109 |
| |
109 | 110 |
| |
110 | 111 |
| |
|
0 commit comments
Comments
(0)