1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

pg_dump: label INDEX ATTACH ArchiveEntries with an owner.

Although a partitioned index's attachment to its parent doesn't
have separate ownership, the ArchiveEntry for it needs to be
marked with an owner anyway, to ensure that the ALTER command
is run by the appropriate role when restoring with
--use-set-session-authorization.  Without this, the ALTER will
be run by the role that started the restore session, which will
usually work but it's formally the wrong thing.

Back-patch to v11 where this type of ArchiveEntry was added.
In HEAD, add equivalent commentary to the just-added TABLE ATTACH
case, which I'd made do the right thing already.

Discussion: https://postgr.es/m/1094034.1610418498@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2021-01-12 13:37:38 -05:00
parent cc865c0f31
commit 9eabfe300a

View File

@ -16404,6 +16404,13 @@ dumpTableAttach(Archive *fout, TableAttachInfo *attachinfo)
fmtQualifiedDumpable(attachinfo->partitionTbl), fmtQualifiedDumpable(attachinfo->partitionTbl),
attachinfo->partitionTbl->partbound); attachinfo->partitionTbl->partbound);
/*
* There is no point in creating a drop query as the drop is done by table
* drop. (If you think to change this, see also _printTocEntry().)
* 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,
.namespace = attachinfo->dobj.namespace->dobj.name, .namespace = attachinfo->dobj.namespace->dobj.name,
@ -16685,9 +16692,17 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo)
appendPQExpBuffer(q, "ATTACH PARTITION %s;\n", appendPQExpBuffer(q, "ATTACH PARTITION %s;\n",
fmtQualifiedDumpable(attachinfo->partitionIdx)); fmtQualifiedDumpable(attachinfo->partitionIdx));
/*
* There is no point in creating a drop query as the drop is done by
* index drop. (If you think to change this, see also
* _printTocEntry().) 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,
.namespace = attachinfo->dobj.namespace->dobj.name, .namespace = attachinfo->dobj.namespace->dobj.name,
.owner = attachinfo->parentIdx->indextable->rolname,
.description = "INDEX ATTACH", .description = "INDEX ATTACH",
.section = SECTION_POST_DATA, .section = SECTION_POST_DATA,
.createStmt = q->data)); .createStmt = q->data));