fix-ext-sequence-config-dump.patch
text/x-patch
Filename: fix-ext-sequence-config-dump.patch
Type: text/x-patch
Part: 0
Message:
Re: [9.1] 2 bugs with extensions
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| src/bin/pg_dump/pg_dump.c | 54 | 0 |
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
***************
*** 181,187 **** static void dumpTrigger(Archive *fout, TriggerInfo *tginfo);
static void dumpTable(Archive *fout, TableInfo *tbinfo);
static void dumpTableSchema(Archive *fout, TableInfo *tbinfo);
static void dumpAttrDef(Archive *fout, AttrDefInfo *adinfo);
! static void dumpSequence(Archive *fout, TableInfo *tbinfo);
static void dumpIndex(Archive *fout, IndxInfo *indxinfo);
static void dumpConstraint(Archive *fout, ConstraintInfo *coninfo);
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo);
--- 181,187 ----
static void dumpTable(Archive *fout, TableInfo *tbinfo);
static void dumpTableSchema(Archive *fout, TableInfo *tbinfo);
static void dumpAttrDef(Archive *fout, AttrDefInfo *adinfo);
! static void dumpSequence(Archive *fout, TableInfo *tbinfo, bool extMember);
static void dumpIndex(Archive *fout, IndxInfo *indxinfo);
static void dumpConstraint(Archive *fout, ConstraintInfo *coninfo);
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo);
***************
*** 1536,1541 **** dumpTableData(Archive *fout, TableDataInfo *tdinfo)
--- 1536,1547 ----
DataDumperPtr dumpFn;
char *copyStmt;
+ if (tbinfo->relkind == RELKIND_SEQUENCE)
+ {
+ dumpSequence(fout, tbinfo, true);
+ return;
+ }
+
if (!dump_inserts)
{
/* Dump/restore using COPY */
***************
*** 1604,1609 **** makeTableDataInfo(TableInfo *tbinfo, bool oids)
--- 1610,1630 ----
{
TableDataInfo *tdinfo;
+ /*
+ * Nothing to do if we already decided to dump the table. This will
+ * happen for "config" tables.
+ */
+ if (tbinfo->dataObj != NULL)
+ return;
+
+ /* Skip VIEWs (no data to dump) */
+ if (tbinfo->relkind == RELKIND_VIEW)
+ return;
+ /* Skip FOREIGN TABLEs (no data to dump) */
+ if (tbinfo->relkind == RELKIND_FOREIGN_TABLE)
+ return;
+
+ /* OK, let's dump it */
tdinfo = (TableDataInfo *) malloc(sizeof(TableDataInfo));
tdinfo->dobj.objType = DO_TABLE_DATA;
***************
*** 11975,11981 **** dumpTable(Archive *fout, TableInfo *tbinfo)
char *namecopy;
if (tbinfo->relkind == RELKIND_SEQUENCE)
! dumpSequence(fout, tbinfo);
else if (!dataOnly)
dumpTableSchema(fout, tbinfo);
--- 11996,12002 ----
char *namecopy;
if (tbinfo->relkind == RELKIND_SEQUENCE)
! dumpSequence(fout, tbinfo, false);
else if (!dataOnly)
dumpTableSchema(fout, tbinfo);
***************
*** 13118,13124 **** findLastBuiltinOid_V70(void)
}
static void
! dumpSequence(Archive *fout, TableInfo *tbinfo)
{
PGresult *res;
char *startv,
--- 13139,13145 ----
}
static void
! dumpSequence(Archive *fout, TableInfo *tbinfo, bool extMember)
{
PGresult *res;
char *startv,
***************
*** 13219,13225 **** dumpSequence(Archive *fout, TableInfo *tbinfo)
*
* Add a 'SETVAL(seq, last_val, iscalled)' as part of a "data" dump.
*/
! if (!dataOnly)
{
/*
* DROP must be fully qualified in case same name appears in
--- 13240,13246 ----
*
* Add a 'SETVAL(seq, last_val, iscalled)' as part of a "data" dump.
*/
! if (!extMember && !dataOnly)
{
/*
* DROP must be fully qualified in case same name appears in
***************
*** 13338,13344 **** dumpSequence(Archive *fout, TableInfo *tbinfo)
tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
}
! if (!schemaOnly)
{
resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT pg_catalog.setval(");
--- 13359,13365 ----
tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
}
! if (extMember || !schemaOnly)
{
resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT pg_catalog.setval(");
***************
*** 13837,13852 **** getExtensionMembership(ExtensionInfo extinfo[], int numExtensions)
TableInfo *configtbl;
configtbl = findTableByOid(atooid(extconfigarray[j]));
! if (configtbl && configtbl->dataObj == NULL)
{
! /*
! * Note: config tables are dumped without OIDs regardless
! * of the --oids setting. This is because row filtering
! * conditions aren't compatible with dumping OIDs.
! */
! makeTableDataInfo(configtbl, false);
! if (strlen(extconditionarray[j]) > 0)
! configtbl->dataObj->filtercond = strdup(extconditionarray[j]);
}
}
}
--- 13858,13892 ----
TableInfo *configtbl;
configtbl = findTableByOid(atooid(extconfigarray[j]));
! if (configtbl == NULL)
! continue;
!
! /*
! * Note: config tables are dumped without OIDs regardless of
! * the --oids setting. This is because row filtering conditions
! * aren't compatible with dumping OIDs.
! */
! switch (configtbl->relkind)
{
! case RELKIND_SEQUENCE:
! makeTableDataInfo(configtbl, false);
! break;
!
! case RELKIND_RELATION:
! case RELKIND_VIEW:
! makeTableDataInfo(configtbl, false);
! if (configtbl->dataObj != NULL)
! configtbl->dataObj->filtercond =
! pg_strdup(extconditionarray[j]);
! break;
!
! case RELKIND_INDEX:
! case RELKIND_TOASTVALUE:
! case RELKIND_COMPOSITE_TYPE:
! case RELKIND_FOREIGN_TABLE:
! case RELKIND_UNCATALOGED:
! /* not supported as an extension config dump target */
! break;
}
}
}