@@ -202,6 +202,7 @@ static void dumpTrigger(Archive *fout, TriggerInfo *tginfo);
202
202
static void dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo);
203
203
static void dumpTable(Archive *fout, TableInfo *tbinfo);
204
204
static void dumpTableSchema(Archive *fout, TableInfo *tbinfo);
205
+ static void dumpTableAttach(Archive *fout, TableAttachInfo *tbinfo);
205
206
static void dumpAttrDef(Archive *fout, AttrDefInfo *adinfo);
206
207
static void dumpSequence(Archive *fout, TableInfo *tbinfo);
207
208
static void dumpSequenceData(Archive *fout, TableDataInfo *tdinfo);
@@ -10176,6 +10177,9 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj)
10176
10177
case DO_TABLE:
10177
10178
dumpTable(fout, (TableInfo *) dobj);
10178
10179
break;
10180
+ case DO_TABLE_ATTACH:
10181
+ dumpTableAttach(fout, (TableAttachInfo *) dobj);
10182
+ break;
10179
10183
case DO_ATTRDEF:
10180
10184
dumpAttrDef(fout, (AttrDefInfo *) dobj);
10181
10185
break;
@@ -11183,7 +11187,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
11183
11187
if (dopt->binary_upgrade)
11184
11188
binary_upgrade_set_type_oids_by_type_oid(fout, q,
11185
11189
tyinfo->dobj.catId.oid,
11186
- true, /* force array type */
11190
+ true, /* force array type */
11187
11191
false); /* force multirange type */
11188
11192
11189
11193
qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
@@ -16133,27 +16137,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
16133
16137
}
16134
16138
}
16135
16139
16136
- /*
16137
- * For partitioned tables, emit the ATTACH PARTITION clause. Note
16138
- * that we always want to create partitions this way instead of using
16139
- * CREATE TABLE .. PARTITION OF, mainly to preserve a possible column
16140
- * layout discrepancy with the parent, but also to ensure it gets the
16141
- * correct tablespace setting if it differs from the parent's.
16142
- */
16143
- if (tbinfo->ispartition)
16144
- {
16145
- /* With partitions there can only be one parent */
16146
- if (tbinfo->numParents != 1)
16147
- fatal("invalid number of parents %d for table \"%s\"",
16148
- tbinfo->numParents, tbinfo->dobj.name);
16149
-
16150
- /* Perform ALTER TABLE on the parent */
16151
- appendPQExpBuffer(q,
16152
- "ALTER TABLE ONLY %s ATTACH PARTITION %s %s;\n",
16153
- fmtQualifiedDumpable(parents[0]),
16154
- qualrelname, tbinfo->partbound);
16155
- }
16156
-
16157
16140
/*
16158
16141
* In binary_upgrade mode, arrange to restore the old relfrozenxid and
16159
16142
* relminmxid of all vacuumable relations. (While vacuum.c processes
@@ -16383,6 +16366,55 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
16383
16366
free(qualrelname);
16384
16367
}
16385
16368
16369
+ /*
16370
+ * dumpTableAttach
16371
+ * write to fout the commands to attach a child partition
16372
+ *
16373
+ * Child partitions are always made by creating them separately
16374
+ * and then using ATTACH PARTITION, rather than using
16375
+ * CREATE TABLE ... PARTITION OF. This is important for preserving
16376
+ * any possible discrepancy in column layout, to allow assigning the
16377
+ * correct tablespace if different, and so that it's possible to restore
16378
+ * a partition without restoring its parent. (You'll get an error from
16379
+ * the ATTACH PARTITION command, but that can be ignored, or skipped
16380
+ * using "pg_restore -L" if you prefer.) The last point motivates
16381
+ * treating ATTACH PARTITION as a completely separate ArchiveEntry
16382
+ * rather than emitting it within the child partition's ArchiveEntry.
16383
+ */
16384
+ static void
16385
+ dumpTableAttach(Archive *fout, TableAttachInfo *attachinfo)
16386
+ {
16387
+ DumpOptions *dopt = fout->dopt;
16388
+ PQExpBuffer q;
16389
+
16390
+ if (dopt->dataOnly)
16391
+ return;
16392
+
16393
+ if (!(attachinfo->partitionTbl->dobj.dump & DUMP_COMPONENT_DEFINITION))
16394
+ return;
16395
+
16396
+ q = createPQExpBuffer();
16397
+
16398
+ /* Perform ALTER TABLE on the parent */
16399
+ appendPQExpBuffer(q,
16400
+ "ALTER TABLE ONLY %s ",
16401
+ fmtQualifiedDumpable(attachinfo->parentTbl));
16402
+ appendPQExpBuffer(q,
16403
+ "ATTACH PARTITION %s %s;\n",
16404
+ fmtQualifiedDumpable(attachinfo->partitionTbl),
16405
+ attachinfo->partitionTbl->partbound);
16406
+
16407
+ ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId,
16408
+ ARCHIVE_OPTS(.tag = attachinfo->dobj.name,
16409
+ .namespace = attachinfo->dobj.namespace->dobj.name,
16410
+ .owner = attachinfo->partitionTbl->rolname,
16411
+ .description = "TABLE ATTACH",
16412
+ .section = SECTION_PRE_DATA,
16413
+ .createStmt = q->data));
16414
+
16415
+ destroyPQExpBuffer(q);
16416
+ }
16417
+
16386
16418
/*
16387
16419
* dumpAttrDef --- dump an attribute's default-value declaration
16388
16420
*/
@@ -18344,6 +18376,7 @@ addBoundaryDependencies(DumpableObject **dobjs, int numObjs,
18344
18376
case DO_COLLATION:
18345
18377
case DO_CONVERSION:
18346
18378
case DO_TABLE:
18379
+ case DO_TABLE_ATTACH:
18347
18380
case DO_ATTRDEF:
18348
18381
case DO_PROCLANG:
18349
18382
case DO_CAST:
0 commit comments