Skip to content

Commit 1fc3403

Browse files
committed
Fix pg_dump --clean with partitioned indexes.
We'd try to drop the partitions of a partitioned index separately, which is disallowed by the backend, leading to an error during restore. While the error is harmless, it causes problems if you try to use --single-transaction mode. Fortunately, there seems no need to do a DROP at all, since the partition will go away silently when we drop either the parent index or the partition's table. So just make the DROP conditional on not being a partition. Reported-by: jian he <jian.universality@gmail.com> Author: jian he <jian.universality@gmail.com> Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CACJufxF0QSdkjFKF4di-JGWN6CSdQYEAhGPmQJJCdkSZtd=oLg@mail.gmail.com Backpatch-through: 13
1 parent 40b9c27 commit 1fc3403

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17953,7 +17953,17 @@ dumpIndex(Archive *fout, const IndxInfo *indxinfo)
1795317953
qindxname);
1795417954
}
1795517955

17956-
appendPQExpBuffer(delq, "DROP INDEX %s;\n", qqindxname);
17956+
/*
17957+
* If this index is a member of a partitioned index, the backend will
17958+
* not allow us to drop it separately, so don't try. It will go away
17959+
* automatically when we drop either the index's table or the
17960+
* partitioned index. (If, in a selective restore with --clean, we
17961+
* drop neither of those, then this index will not be dropped either.
17962+
* But that's fine, and even if you think it's not, the backend won't
17963+
* let us do differently.)
17964+
*/
17965+
if (indxinfo->parentidx == 0)
17966+
appendPQExpBuffer(delq, "DROP INDEX %s;\n", qqindxname);
1795717967

1795817968
if (indxinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
1795917969
ArchiveEntry(fout, indxinfo->dobj.catId, indxinfo->dobj.dumpId,
@@ -18006,11 +18016,15 @@ dumpIndexAttach(Archive *fout, const IndexAttachInfo *attachinfo)
1800618016
fmtQualifiedDumpable(attachinfo->partitionIdx));
1800718017

1800818018
/*
18009-
* There is no point in creating a drop query as the drop is done by
18010-
* index drop. (If you think to change this, see also
18011-
* _printTocEntry().) Although this object doesn't really have
18012-
* ownership as such, set the owner field anyway to ensure that the
18013-
* command is run by the correct role at restore time.
18019+
* There is no need for a dropStmt since the drop is done implicitly
18020+
* when we drop either the index's table or the partitioned index.
18021+
* Moreover, since there's no ALTER INDEX DETACH PARTITION command,
18022+
* there's no way to do it anyway. (If you think to change this,
18023+
* consider also what to do with --if-exists.)
18024+
*
18025+
* Although this object doesn't really have ownership as such, set the
18026+
* owner field anyway to ensure that the command is run by the correct
18027+
* role at restore time.
1801418028
*/
1801518029
ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId,
1801618030
ARCHIVE_OPTS(.tag = attachinfo->dobj.name,

0 commit comments

Comments
 (0)