Skip to content

Commit addf9e1

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/1e6cc5ad-b84a-7c07-8c08-a4d0c3cdc938@matrix.gatewaynet.com
1 parent 5649332 commit addf9e1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13799,6 +13799,12 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1379913799
/* Plain secondary index */
1380013800
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
1380113801

13802+
/*
13803+
* Append ALTER TABLE commands as needed to set properties that we
13804+
* only have ALTER TABLE syntax for. Keep this in sync with the
13805+
* similar code in dumpConstraint!
13806+
*/
13807+
1380213808
/* If the index is clustered, we need to record that. */
1380313809
if (indxinfo->indisclustered)
1380413810
{
@@ -13929,6 +13935,12 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
1392913935
appendPQExpBufferStr(q, ";\n");
1393013936
}
1393113937

13938+
/*
13939+
* Append ALTER TABLE commands as needed to set properties that we
13940+
* only have ALTER TABLE syntax for. Keep this in sync with the
13941+
* similar code in dumpIndex!
13942+
*/
13943+
1393213944
/* If the index is clustered, we need to record that. */
1393313945
if (indxinfo->indisclustered)
1393413946
{
@@ -13939,6 +13951,16 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
1393913951
fmtId(indxinfo->dobj.name));
1394013952
}
1394113953

13954+
/* If the index defines identity, we need to record that. */
13955+
if (indxinfo->indisreplident)
13956+
{
13957+
appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY USING",
13958+
fmtQualifiedDumpable(tbinfo));
13959+
/* index name is not qualified in this syntax */
13960+
appendPQExpBuffer(q, " INDEX %s;\n",
13961+
fmtId(indxinfo->dobj.name));
13962+
}
13963+
1394213964
appendPQExpBuffer(delq, "ALTER TABLE ONLY %s ",
1394313965
fmtQualifiedDumpable(tbinfo));
1394413966
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",

0 commit comments

Comments
 (0)