forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf8dc198
committed
Fix ALTER SEQUENCE locking
In1753b1b, the pg_sequence systemcatalog was introduced. This made sequence metadata changestransactional, while the actual sequence values are still behavingnontransactionally. This requires some refinement in how ALTERSEQUENCE, which operates on both, locks the sequence and the catalog.The main problems were:- Concurrent ALTER SEQUENCE causes "tuple concurrently updated" error, caused by updates to pg_sequence catalog.- Sequence WAL writes and catalog updates are not protected by same lock, which could lead to inconsistent recovery order.- nextval() disregarding uncommitted ALTER SEQUENCE changes.To fix, nextval() and friends now lock the sequence usingRowExclusiveLock instead of AccessShareLock. ALTER SEQUENCE locks thesequence using ShareRowExclusiveLock. This means that nextval() andALTER SEQUENCE block each other, and ALTER SEQUENCE on the same sequenceblocks itself. (This was already the case previously for the OWNER TO,RENAME, and SET SCHEMA variants.) Also, rearrange some code so that theentire AlterSequence is protected by the lock on the sequence.As an exception, use reduced locking for ALTER SEQUENCE ... RESTART.Since that is basically a setval(), it does not require the full lockingof other ALTER SEQUENCE actions. So check whether we are only running aRESTART and run with less locking if so.Reviewed-by: Michael Paquier <michael.paquier@gmail.com>Reported-by: Jason Petersen <jason@citusdata.com>Reported-by: Andres Freund <andres@anarazel.de>1 parentb1c45af commitf8dc198
File tree
5 files changed
+180
-21
lines changed- doc/src/sgml/ref
- src
- backend/commands
- test/isolation
- expected
- specs
5 files changed
+180
-21
lines changedLines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
304 | 304 |
| |
305 | 305 |
| |
306 | 306 |
| |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
307 | 314 |
| |
308 | 315 |
| |
309 | 316 |
| |
|
Lines changed: 48 additions & 21 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
93 | 93 |
| |
94 | 94 |
| |
95 | 95 |
| |
96 |
| - | |
| 96 | + | |
97 | 97 |
| |
98 | 98 |
| |
99 | 99 |
| |
100 | 100 |
| |
| 101 | + | |
101 | 102 |
| |
102 | 103 |
| |
103 | 104 |
| |
| |||
427 | 428 |
| |
428 | 429 |
| |
429 | 430 |
| |
430 |
| - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
431 | 434 |
| |
432 | 435 |
| |
433 | 436 |
| |
| |||
443 | 446 |
| |
444 | 447 |
| |
445 | 448 |
| |
446 |
| - | |
447 |
| - | |
448 |
| - | |
449 |
| - | |
450 |
| - | |
451 |
| - | |
452 | 449 |
| |
453 | 450 |
| |
454 | 451 |
| |
| |||
458 | 455 |
| |
459 | 456 |
| |
460 | 457 |
| |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
461 | 464 |
| |
462 | 465 |
| |
463 | 466 |
| |
| |||
508 | 511 |
| |
509 | 512 |
| |
510 | 513 |
| |
511 |
| - | |
512 |
| - | |
513 | 514 |
| |
514 | 515 |
| |
515 | 516 |
| |
516 | 517 |
| |
| 518 | + | |
| 519 | + | |
517 | 520 |
| |
518 | 521 |
| |
519 | 522 |
| |
| |||
594 | 597 |
| |
595 | 598 |
| |
596 | 599 |
| |
597 |
| - | |
| 600 | + | |
598 | 601 |
| |
599 | 602 |
| |
600 | 603 |
| |
| |||
829 | 832 |
| |
830 | 833 |
| |
831 | 834 |
| |
832 |
| - | |
| 835 | + | |
833 | 836 |
| |
834 | 837 |
| |
835 | 838 |
| |
| |||
869 | 872 |
| |
870 | 873 |
| |
871 | 874 |
| |
872 |
| - | |
| 875 | + | |
873 | 876 |
| |
874 | 877 |
| |
875 | 878 |
| |
| |||
913 | 916 |
| |
914 | 917 |
| |
915 | 918 |
| |
916 |
| - | |
| 919 | + | |
917 | 920 |
| |
918 | 921 |
| |
919 | 922 |
| |
| |||
1042 | 1045 |
| |
1043 | 1046 |
| |
1044 | 1047 |
| |
1045 |
| - | |
| 1048 | + | |
1046 | 1049 |
| |
1047 | 1050 |
| |
1048 |
| - | |
| 1051 | + | |
1049 | 1052 |
| |
1050 | 1053 |
| |
1051 | 1054 |
| |
1052 | 1055 |
| |
1053 |
| - | |
| 1056 | + | |
1054 | 1057 |
| |
1055 | 1058 |
| |
1056 | 1059 |
| |
| |||
1063 | 1066 |
| |
1064 | 1067 |
| |
1065 | 1068 |
| |
1066 |
| - | |
| 1069 | + | |
1067 | 1070 |
| |
1068 | 1071 |
| |
1069 | 1072 |
| |
| |||
1078 | 1081 |
| |
1079 | 1082 |
| |
1080 | 1083 |
| |
1081 |
| - | |
| 1084 | + | |
1082 | 1085 |
| |
1083 | 1086 |
| |
1084 | 1087 |
| |
| |||
1135 | 1138 |
| |
1136 | 1139 |
| |
1137 | 1140 |
| |
1138 |
| - | |
| 1141 | + | |
1139 | 1142 |
| |
1140 | 1143 |
| |
1141 | 1144 |
| |
| |||
1216 | 1219 |
| |
1217 | 1220 |
| |
1218 | 1221 |
| |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
1219 | 1246 |
| |
1220 | 1247 |
| |
1221 | 1248 |
| |
| |||
1850 | 1877 |
| |
1851 | 1878 |
| |
1852 | 1879 |
| |
1853 |
| - | |
| 1880 | + | |
1854 | 1881 |
| |
1855 | 1882 |
| |
1856 | 1883 |
| |
|
Lines changed: 85 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 | + |
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
58 | 58 |
| |
59 | 59 |
| |
60 | 60 |
| |
| 61 | + | |
61 | 62 |
| |
62 | 63 |
| |
63 | 64 |
|
Lines changed: 39 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 | + |
0 commit comments
Comments
(0)