|
49 | 49 | #include "catalog/pg_class_d.h"
|
50 | 50 | #include "catalog/pg_default_acl_d.h"
|
51 | 51 | #include "catalog/pg_largeobject_d.h"
|
| 52 | +#include "catalog/pg_largeobject_metadata_d.h" |
52 | 53 | #include "catalog/pg_proc_d.h"
|
53 | 54 | #include "catalog/pg_publication_d.h"
|
| 55 | +#include "catalog/pg_shdepend.h" |
54 | 56 | #include "catalog/pg_subscription_d.h"
|
55 | 57 | #include "catalog/pg_type_d.h"
|
56 | 58 | #include "common/connect.h"
|
@@ -209,6 +211,12 @@ static int nbinaryUpgradeClassOids = 0;
|
209 | 211 | static SequenceItem *sequences = NULL;
|
210 | 212 | static int nsequences = 0;
|
211 | 213 |
|
| 214 | +/* |
| 215 | + * For binary upgrade, the dump ID of pg_largeobject_metadata is saved for use |
| 216 | + * as a dependency for pg_shdepend and any large object comments/seclabels. |
| 217 | + */ |
| 218 | +static DumpId lo_metadata_dumpId; |
| 219 | + |
212 | 220 | /* Maximum number of relations to fetch in a fetchAttributeStats() call. */
|
213 | 221 | #define MAX_ATTR_STATS_RELS 64
|
214 | 222 |
|
@@ -1083,6 +1091,34 @@ main(int argc, char **argv)
|
1083 | 1091 | if (!dopt.dumpData && dopt.sequence_data)
|
1084 | 1092 | getTableData(&dopt, tblinfo, numTables, RELKIND_SEQUENCE);
|
1085 | 1093 |
|
| 1094 | + /* |
| 1095 | + * For binary upgrade mode, dump pg_largeobject_metadata and the |
| 1096 | + * associated pg_shdepend rows. This is faster to restore than the |
| 1097 | + * equivalent set of large object commands. |
| 1098 | + */ |
| 1099 | + if (dopt.binary_upgrade && fout->remoteVersion >= 120000) |
| 1100 | + { |
| 1101 | + TableInfo *lo_metadata = findTableByOid(LargeObjectMetadataRelationId); |
| 1102 | + TableInfo *shdepend = findTableByOid(SharedDependRelationId); |
| 1103 | + |
| 1104 | + makeTableDataInfo(&dopt, lo_metadata); |
| 1105 | + makeTableDataInfo(&dopt, shdepend); |
| 1106 | + |
| 1107 | + /* |
| 1108 | + * Save pg_largeobject_metadata's dump ID for use as a dependency on |
| 1109 | + * pg_shdepend and any large object comments/seclabels. |
| 1110 | + */ |
| 1111 | + lo_metadata_dumpId = lo_metadata->dataObj->dobj.dumpId; |
| 1112 | + addObjectDependency(&shdepend->dataObj->dobj, lo_metadata_dumpId); |
| 1113 | + |
| 1114 | + /* |
| 1115 | + * Only dump large object shdepend rows for this database. |
| 1116 | + */ |
| 1117 | + shdepend->dataObj->filtercond = "WHERE classid = 'pg_largeobject'::regclass " |
| 1118 | + "AND dbid = (SELECT oid FROM pg_database " |
| 1119 | + " WHERE datname = current_database())"; |
| 1120 | + } |
| 1121 | + |
1086 | 1122 | /*
|
1087 | 1123 | * In binary-upgrade mode, we do not have to worry about the actual LO
|
1088 | 1124 | * data or the associated metadata that resides in the pg_largeobject and
|
@@ -3922,10 +3958,29 @@ getLOs(Archive *fout)
|
3922 | 3958 | * as it will be copied by pg_upgrade, which simply copies the
|
3923 | 3959 | * pg_largeobject table. We *do* however dump out anything but the
|
3924 | 3960 | * data, as pg_upgrade copies just pg_largeobject, but not
|
3925 |
| - * pg_largeobject_metadata, after the dump is restored. |
| 3961 | + * pg_largeobject_metadata, after the dump is restored. In versions |
| 3962 | + * before v12, this is done via proper large object commands. In |
| 3963 | + * newer versions, we dump the content of pg_largeobject_metadata and |
| 3964 | + * any associated pg_shdepend rows, which is faster to restore. |
3926 | 3965 | */
|
3927 | 3966 | if (dopt->binary_upgrade)
|
3928 |
| - loinfo->dobj.dump &= ~DUMP_COMPONENT_DATA; |
| 3967 | + { |
| 3968 | + if (fout->remoteVersion >= 120000) |
| 3969 | + { |
| 3970 | + loinfo->dobj.dump &= ~(DUMP_COMPONENT_DATA | DUMP_COMPONENT_ACL | DUMP_COMPONENT_DEFINITION); |
| 3971 | + |
| 3972 | + /* |
| 3973 | + * Mark the large object as dependent on |
| 3974 | + * pg_largeobject_metadata so that any large object |
| 3975 | + * comments/seclables are dumped after it. |
| 3976 | + */ |
| 3977 | + loinfo->dobj.dependencies = (DumpId *) pg_malloc(sizeof(DumpId)); |
| 3978 | + loinfo->dobj.dependencies[0] = lo_metadata_dumpId; |
| 3979 | + loinfo->dobj.nDeps = loinfo->dobj.allocDeps = 1; |
| 3980 | + } |
| 3981 | + else |
| 3982 | + loinfo->dobj.dump &= ~DUMP_COMPONENT_DATA; |
| 3983 | + } |
3929 | 3984 |
|
3930 | 3985 | /*
|
3931 | 3986 | * Create a "BLOBS" data item for the group, too. This is just a
|
@@ -9034,8 +9089,18 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
|
9034 | 9089 | if (tbinfo->relkind == RELKIND_SEQUENCE)
|
9035 | 9090 | continue;
|
9036 | 9091 |
|
9037 |
| - /* Don't bother with uninteresting tables, either */ |
9038 |
| - if (!tbinfo->interesting) |
| 9092 | + /* |
| 9093 | + * Don't bother with uninteresting tables, either. For binary |
| 9094 | + * upgrades, this is bypassed for pg_largeobject_metadata and |
| 9095 | + * pg_shdepend so that the columns names are collected for the |
| 9096 | + * corresponding COPY commands. Restoring the data for those catalogs |
| 9097 | + * is faster than restoring the equivalent set of large object |
| 9098 | + * commands. |
| 9099 | + */ |
| 9100 | + if (!tbinfo->interesting && |
| 9101 | + !(fout->dopt->binary_upgrade && fout->remoteVersion >= 120000 && |
| 9102 | + (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId || |
| 9103 | + tbinfo->dobj.catId.oid == SharedDependRelationId))) |
9039 | 9104 | continue;
|
9040 | 9105 |
|
9041 | 9106 | /* OK, we need info for this table */
|
@@ -9232,7 +9297,10 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
|
9232 | 9297 | pg_fatal("unrecognized table OID %u", attrelid);
|
9233 | 9298 | /* cross-check that we only got requested tables */
|
9234 | 9299 | if (tbinfo->relkind == RELKIND_SEQUENCE ||
|
9235 |
| - !tbinfo->interesting) |
| 9300 | + (!tbinfo->interesting && |
| 9301 | + !(fout->dopt->binary_upgrade && fout->remoteVersion >= 120000 && |
| 9302 | + (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId || |
| 9303 | + tbinfo->dobj.catId.oid == SharedDependRelationId)))) |
9236 | 9304 | pg_fatal("unexpected column data for table \"%s\"",
|
9237 | 9305 | tbinfo->dobj.name);
|
9238 | 9306 |
|
|
0 commit comments