mirror of
https://github.com/postgres/postgres.git
synced 2025-04-18 13:44:19 +03:00
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
This commit is contained in:
parent
97d6716723
commit
7144cd5382
@ -16381,6 +16381,16 @@ dumpIndex(Archive *fout, const IndxInfo *indxinfo)
|
|||||||
qindxname);
|
qindxname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If this index is a member of a partitioned index, the backend will
|
||||||
|
* not allow us to drop it separately, so don't try. It will go away
|
||||||
|
* automatically when we drop either the index's table or the
|
||||||
|
* partitioned index. (If, in a selective restore with --clean, we
|
||||||
|
* drop neither of those, then this index will not be dropped either.
|
||||||
|
* But that's fine, and even if you think it's not, the backend won't
|
||||||
|
* let us do differently.)
|
||||||
|
*/
|
||||||
|
if (indxinfo->parentidx == 0)
|
||||||
appendPQExpBuffer(delq, "DROP INDEX %s;\n", qqindxname);
|
appendPQExpBuffer(delq, "DROP INDEX %s;\n", qqindxname);
|
||||||
|
|
||||||
if (indxinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
|
if (indxinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
|
||||||
@ -16436,11 +16446,15 @@ dumpIndexAttach(Archive *fout, const IndexAttachInfo *attachinfo)
|
|||||||
fmtQualifiedDumpable(attachinfo->partitionIdx));
|
fmtQualifiedDumpable(attachinfo->partitionIdx));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There is no point in creating a drop query as the drop is done by
|
* There is no need for a dropStmt since the drop is done implicitly
|
||||||
* index drop. (If you think to change this, see also
|
* when we drop either the index's table or the partitioned index.
|
||||||
* _printTocEntry().) Although this object doesn't really have
|
* Moreover, since there's no ALTER INDEX DETACH PARTITION command,
|
||||||
* ownership as such, set the owner field anyway to ensure that the
|
* there's no way to do it anyway. (If you think to change this,
|
||||||
* command is run by the correct role at restore time.
|
* consider also what to do with --if-exists.)
|
||||||
|
*
|
||||||
|
* Although this object doesn't really have ownership as such, set the
|
||||||
|
* owner field anyway to ensure that the command is run by the correct
|
||||||
|
* role at restore time.
|
||||||
*/
|
*/
|
||||||
ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId,
|
ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId,
|
||||||
ARCHIVE_OPTS(.tag = attachinfo->dobj.name,
|
ARCHIVE_OPTS(.tag = attachinfo->dobj.name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user