forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbc8cd50
committed
Fix pg_dump for hash partitioning on enum columns.
Hash partitioning on an enum is problematic because the hash codes arederived from the OIDs assigned to the enum values, which will almostcertainly be different after a dump-and-reload than they were before.This means that some rows probably end up in different partitions thanbefore, causing restore to fail because of partition constraintviolations. (pg_upgrade dodges this problem by using hacks to forcethe enum values to keep the same OIDs, but that's not possible nordesirable for pg_dump.)Users can work around that by specifying --load-via-partition-root,but since that's a dump-time not restore-time decision, one mightfind out the need for it far too late. Instead, teach pg_dump toapply that option automatically when dealing with a partitionedtable that has hash-on-enum partitioning.Also deal with a pre-existing issue for --load-via-partition-rootmode: in a parallel restore, we try to TRUNCATE target tables justbefore loading them, in order to enable some backend optimizations.This is bad when using --load-via-partition-root because (a) we'relikely to suffer deadlocks from restore jobs trying to restore rowsinto other partitions than they came from, and (b) if we miss gettinga deadlock we might still lose data due to a TRUNCATE removing rowsfrom some already-completed restore job.The fix for this is conceptually simple: just don't TRUNCATE if we'redealing with a --load-via-partition-root case. The tricky bit is forpg_restore to identify those cases. In dumps using COPY commands wecan inspect each COPY command to see if it targets the nominal targettable or some ancestor. However, in dumps using INSERT commands it'spretty impractical to examine the INSERTs in advance. To provide asolution for that going forward, modify pg_dump to mark TABLE DATAitems that are using --load-via-partition-root with a comment.(This change also responds to a complaint from Robert Haas thatthe dump output for --load-via-partition-root is pretty confusing.)pg_restore checks for the special comment as well as checking theCOPY command if present. This will fail to identify the combinationof --load-via-partition-root and --inserts in pre-existing dump files,but that should be a pretty rare case in the field. If it doeshappen you will probably get a deadlock failure that you can workaround by not using parallel restore, which is the same as beforethis bug fix.Having done this, there seems no remaining reason for the alarmismin the pg_dump man page about combining --load-via-partition-rootwith parallel restore, so remove that warning.Patch by me; thanks to Julien Rouhaud for review. Back-patch tov11 where hash partitioning was introduced.Discussion:https://postgr.es/m/1376149.1675268279@sss.pgh.pa.us1 parentde4d456 commitbc8cd50
File tree
8 files changed
+288
-52
lines changed- doc/src/sgml/ref
- src/bin/pg_dump
- t
8 files changed
+288
-52
lines changedLines changed: 0 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
903 | 903 |
| |
904 | 904 |
| |
905 | 905 |
| |
906 |
| - | |
907 |
| - | |
908 |
| - | |
909 |
| - | |
910 |
| - | |
911 |
| - | |
912 |
| - | |
913 |
| - | |
914 |
| - | |
915 |
| - | |
916 | 906 |
| |
917 | 907 |
| |
918 | 908 |
| |
|
Lines changed: 0 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
361 | 361 |
| |
362 | 362 |
| |
363 | 363 |
| |
364 |
| - | |
365 |
| - | |
366 |
| - | |
367 |
| - | |
368 | 364 |
| |
369 | 365 |
| |
370 | 366 |
| |
|
Lines changed: 10 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
230 | 230 |
| |
231 | 231 |
| |
232 | 232 |
| |
| 233 | + | |
| 234 | + | |
| 235 | + | |
233 | 236 |
| |
234 | 237 |
| |
235 | 238 |
| |
| |||
285 | 288 |
| |
286 | 289 |
| |
287 | 290 |
| |
288 |
| - | |
289 | 291 |
| |
290 | 292 |
| |
291 | 293 |
| |
| |||
301 | 303 |
| |
302 | 304 |
| |
303 | 305 |
| |
304 |
| - | |
305 |
| - | |
306 |
| - | |
307 |
| - | |
308 |
| - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
309 | 311 |
| |
310 | 312 |
| |
311 | 313 |
| |
312 | 314 |
| |
313 | 315 |
| |
314 |
| - | |
315 |
| - | |
| 316 | + | |
| 317 | + | |
316 | 318 |
| |
317 | 319 |
| |
318 | 320 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
96 | 96 |
| |
97 | 97 |
| |
98 | 98 |
| |
| 99 | + | |
99 | 100 |
| |
100 | 101 |
| |
101 | 102 |
| |
|
Lines changed: 64 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
86 | 86 |
| |
87 | 87 |
| |
88 | 88 |
| |
| 89 | + | |
89 | 90 |
| |
90 | 91 |
| |
91 | 92 |
| |
| |||
887 | 888 |
| |
888 | 889 |
| |
889 | 890 |
| |
| 891 | + | |
| 892 | + | |
890 | 893 |
| |
891 | 894 |
| |
892 | 895 |
| |
| |||
898 | 901 |
| |
899 | 902 |
| |
900 | 903 |
| |
901 |
| - | |
902 |
| - | |
903 |
| - | |
904 |
| - | |
905 |
| - | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
906 | 917 |
| |
907 |
| - | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
908 | 922 |
| |
909 | 923 |
| |
910 | 924 |
| |
| |||
942 | 956 |
| |
943 | 957 |
| |
944 | 958 |
| |
945 |
| - | |
| 959 | + | |
946 | 960 |
| |
947 | 961 |
| |
948 | 962 |
| |
| |||
1036 | 1050 |
| |
1037 | 1051 |
| |
1038 | 1052 |
| |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
1039 | 1090 |
| |
1040 | 1091 |
| |
1041 | 1092 |
| |
| |||
2955 | 3006 |
| |
2956 | 3007 |
| |
2957 | 3008 |
| |
2958 |
| - | |
2959 |
| - | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
2960 | 3015 |
| |
2961 | 3016 |
| |
2962 | 3017 |
| |
|
0 commit comments
Comments
(0)