Skip to content

Commit c0a5529

Browse files
committed
Fix pg_dump's failure to dump REPLICA IDENTITY for constraint indexes.
pg_dump knew about printing ALTER TABLE ... REPLICA IDENTITY USING INDEX for indexes declared as indexes, but it failed to print that for indexes declared as unique or primary-key constraints. Per report from Achilleas Mantzios. This has been broken since the feature was introduced, AFAICS. Back-patch to 9.4. Discussion: https://postgr.es/m/[email protected]
1 parent 9295d7c commit c0a5529

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/bin/pg_dump/pg_dump.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -7141,8 +7141,8 @@ getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
71417141
TableInfo *tbinfo = &tblinfo[i];
71427142

71437143
/*
7144-
* For partitioned tables, foreign keys have no triggers so they
7145-
* must be included anyway in case some foreign keys are defined.
7144+
* For partitioned tables, foreign keys have no triggers so they must
7145+
* be included anyway in case some foreign keys are defined.
71467146
*/
71477147
if ((!tbinfo->hastriggers &&
71487148
tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
@@ -16220,6 +16220,12 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1622016220
/* Plain secondary index */
1622116221
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
1622216222

16223+
/*
16224+
* Append ALTER TABLE commands as needed to set properties that we
16225+
* only have ALTER TABLE syntax for. Keep this in sync with the
16226+
* similar code in dumpConstraint!
16227+
*/
16228+
1622316229
/* If the index is clustered, we need to record that. */
1622416230
if (indxinfo->indisclustered)
1622516231
{
@@ -16469,6 +16475,12 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
1646916475
appendPQExpBufferStr(q, ";\n");
1647016476
}
1647116477

16478+
/*
16479+
* Append ALTER TABLE commands as needed to set properties that we
16480+
* only have ALTER TABLE syntax for. Keep this in sync with the
16481+
* similar code in dumpIndex!
16482+
*/
16483+
1647216484
/* If the index is clustered, we need to record that. */
1647316485
if (indxinfo->indisclustered)
1647416486
{
@@ -16479,6 +16491,16 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
1647916491
fmtId(indxinfo->dobj.name));
1648016492
}
1648116493

16494+
/* If the index defines identity, we need to record that. */
16495+
if (indxinfo->indisreplident)
16496+
{
16497+
appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY USING",
16498+
fmtQualifiedDumpable(tbinfo));
16499+
/* index name is not qualified in this syntax */
16500+
appendPQExpBuffer(q, " INDEX %s;\n",
16501+
fmtId(indxinfo->dobj.name));
16502+
}
16503+
1648216504
appendPQExpBuffer(delq, "ALTER TABLE ONLY %s ",
1648316505
fmtQualifiedDumpable(tbinfo));
1648416506
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",

0 commit comments

Comments
 (0)