- Notifications
You must be signed in to change notification settings - Fork5k
Commit161a3e8
committed
pg_upgrade: Use COPY for large object metadata.
Presently, pg_dump generates commands like SELECT pg_catalog.lo_create('5432'); ALTER LARGE OBJECT 5432 OWNER TO alice; GRANT SELECT ON LARGE OBJECT 5432 TO bob;for each large object. This is particularly slow at restore time,especially when there are tens or hundreds of millions of largeobjects. From reports and personal experience, such slow restoresseem to be most painful when encountered during pg_upgrade. Thiscommit teaches pg_dump to instead dump pg_largeobject_metadata andthe corresponding pg_shdepend rows when in binary upgrade mode,i.e., pg_dump now generates commands like COPY pg_catalog.pg_largeobject_metadata (oid, lomowner, lomacl) FROM stdin; 543216384{alice=rw/alice,bob=r/alice} \. COPY pg_catalog.pg_shdepend (dbid, classid, objid, objsubid, refclassid, refobjid, deptype) FROM stdin; 5261354320126016384o 5261354320126016385a \.Testing indicates the COPY approach can be significantly faster.To do any better, we'd probably need to find a way to copy/linkpg_largeobject_metadata's files during pg_upgrade, which would belimited to upgrades from >= v16 (since commit7b37823 changedthe storage format for aclitem, which is used forpg_largeobject_metadata.lomacl).Note that this change only applies to binary upgrade mode (i.e.,dumps initiated by pg_upgrade) since it inserts rows directly intocatalogs. Also, this optimization can only be used for upgradesfrom >= v12 because pg_largeobject_metadata was created WITH OIDSin older versions, which prevents pg_dump from handlingpg_largeobject_metadata.oid properly. With some extra effort, itmight be possible to support upgrades from older versions, but theadded complexity didn't seem worth it to support versions that willhave been out-of-support for nearly 3 years by the time this changeis released.Experienced hackers may remember that prior to v12, pg_upgradecopied/linked pg_largeobject_metadata's files (see commit12a53c7). Besides the aforementioned storage format issues,this approach failed to transfer the relevant pg_shdepend rows, andpg_dump still had to generate an lo_create() command per largeobject so that creating the dependent comments and security labelsworked. We could perhaps adopt a hybrid approach for upgrades fromv16 and newer (i.e., generate lo_create() commands for each largeobject, copy/link pg_largeobject_metadata's files, and COPY therelevant pg_shdepend rows), but further testing is needed.Reported-by: Hannu Krosing <hannuk@google.com>Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Hannu Krosing <hannuk@google.com>Reviewed-by: Nitin Motiani <nitinmotiani@google.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/CAMT0RQSS-6qLH%2BzYsOeUbAYhop3wmQTkNmQpo5--QRDUR%2BqYmQ%40mail.gmail.com1 parent4c5159a commit161a3e8
File tree
3 files changed
+103
-6
lines changed- src/bin/pg_dump
- t
3 files changed
+103
-6
lines changedLines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
31 | 31 |
| |
32 | 32 |
| |
33 | 33 |
| |
| 34 | + | |
| 35 | + | |
34 | 36 |
| |
35 | 37 |
| |
36 | 38 |
| |
| |||
2974 | 2976 |
| |
2975 | 2977 |
| |
2976 | 2978 |
| |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
2977 | 2992 |
| |
2978 | 2993 |
| |
2979 | 2994 |
| |
|
Lines changed: 85 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
| 52 | + | |
52 | 53 |
| |
53 | 54 |
| |
| 55 | + | |
54 | 56 |
| |
55 | 57 |
| |
56 | 58 |
| |
| |||
209 | 211 |
| |
210 | 212 |
| |
211 | 213 |
| |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
212 | 220 |
| |
213 | 221 |
| |
214 | 222 |
| |
| |||
1085 | 1093 |
| |
1086 | 1094 |
| |
1087 | 1095 |
| |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
1088 | 1126 |
| |
1089 | 1127 |
| |
1090 | 1128 |
| |
| |||
3924 | 3962 |
| |
3925 | 3963 |
| |
3926 | 3964 |
| |
3927 |
| - | |
| 3965 | + | |
| 3966 | + | |
| 3967 | + | |
| 3968 | + | |
| 3969 | + | |
| 3970 | + | |
3928 | 3971 |
| |
3929 | 3972 |
| |
3930 |
| - | |
| 3973 | + | |
| 3974 | + | |
| 3975 | + | |
| 3976 | + | |
| 3977 | + | |
| 3978 | + | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
3931 | 3996 |
| |
3932 | 3997 |
| |
3933 | 3998 |
| |
| |||
9039 | 9104 |
| |
9040 | 9105 |
| |
9041 | 9106 |
| |
9042 |
| - | |
9043 |
| - | |
| 9107 | + | |
| 9108 | + | |
| 9109 | + | |
| 9110 | + | |
| 9111 | + | |
| 9112 | + | |
| 9113 | + | |
| 9114 | + | |
| 9115 | + | |
| 9116 | + | |
| 9117 | + | |
| 9118 | + | |
| 9119 | + | |
| 9120 | + | |
9044 | 9121 |
| |
9045 | 9122 |
| |
9046 | 9123 |
| |
| |||
9244 | 9321 |
| |
9245 | 9322 |
| |
9246 | 9323 |
| |
9247 |
| - | |
| 9324 | + | |
| 9325 | + | |
| 9326 | + | |
| 9327 | + | |
9248 | 9328 |
| |
9249 | 9329 |
| |
9250 | 9330 |
| |
|
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1087 | 1087 |
| |
1088 | 1088 |
| |
1089 | 1089 |
| |
| 1090 | + | |
1090 | 1091 |
| |
1091 | 1092 |
| |
1092 | 1093 |
| |
| |||
1605 | 1606 |
| |
1606 | 1607 |
| |
1607 | 1608 |
| |
| 1609 | + | |
1608 | 1610 |
| |
1609 | 1611 |
| |
1610 | 1612 |
| |
| |||
4612 | 4614 |
| |
4613 | 4615 |
| |
4614 | 4616 |
| |
4615 |
| - | |
4616 | 4617 |
| |
4617 | 4618 |
| |
| 4619 | + | |
4618 | 4620 |
| |
4619 | 4621 |
| |
4620 | 4622 |
| |
|
0 commit comments
Comments
(0)