mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
Issue CREATE SCHEMA as the originally connecting user, with an
AUTHORIZATION clause to specify the desired owner. This allows a superuser to restore schemas owned by users without CREATE-SCHEMA permissions (ie, schemas originally created by a superuser using AUTHORIZATION). --no-owner can be specified to suppress the AUTHORIZATION clause if need be.
This commit is contained in:
parent
6767cebc6f
commit
a9e9abebd9
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.76 2003/09/23 22:48:53 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.77 2003/09/23 23:31:52 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2211,8 +2211,21 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
|
|||||||
(*AH->PrintExtraTocPtr) (AH, te);
|
(*AH->PrintExtraTocPtr) (AH, te);
|
||||||
ahprintf(AH, "--\n\n");
|
ahprintf(AH, "--\n\n");
|
||||||
|
|
||||||
if (strlen(te->defn) > 0)
|
/*
|
||||||
ahprintf(AH, "%s\n\n", te->defn);
|
* Really crude hack for suppressing AUTHORIZATION clause of CREATE SCHEMA
|
||||||
|
* when --no-owner mode is selected. This is ugly, but I see no other
|
||||||
|
* good way ...
|
||||||
|
*/
|
||||||
|
if (AH->ropt && AH->ropt->noOwner && strcmp(te->desc, "SCHEMA") == 0)
|
||||||
|
{
|
||||||
|
ahprintf(AH, "CREATE SCHEMA %s;\n\n\n", te->tag);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* normal case */
|
||||||
|
if (strlen(te->defn) > 0)
|
||||||
|
ahprintf(AH, "%s\n\n", te->defn);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.349 2003/09/23 22:48:53 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.350 2003/09/23 23:31:52 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2879,43 +2879,42 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
|
|||||||
/*
|
/*
|
||||||
* If it's the PUBLIC namespace, don't emit a CREATE SCHEMA record
|
* If it's the PUBLIC namespace, don't emit a CREATE SCHEMA record
|
||||||
* for it, since we expect PUBLIC to exist already in the
|
* for it, since we expect PUBLIC to exist already in the
|
||||||
* destination database. And emit ACL info only if the ACL isn't
|
* destination database. But do emit ACL in case it's not standard,
|
||||||
* the standard value for PUBLIC.
|
* likewise comment.
|
||||||
|
*
|
||||||
|
* Note that ownership is shown in the AUTHORIZATION clause,
|
||||||
|
* while the archive entry is listed with empty owner (causing
|
||||||
|
* it to be emitted with SET SESSION AUTHORIZATION DEFAULT).
|
||||||
|
* This seems the best way of dealing with schemas owned by
|
||||||
|
* users without CREATE SCHEMA privilege. Further hacking has
|
||||||
|
* to be applied for --no-owner mode, though!
|
||||||
*/
|
*/
|
||||||
if (strcmp(nspinfo->nspname, "public") == 0)
|
if (strcmp(nspinfo->nspname, "public") != 0)
|
||||||
{
|
|
||||||
if (!aclsSkip && strcmp(nspinfo->nspacl, "{=UC}") != 0)
|
|
||||||
dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
|
|
||||||
nspinfo->usename, nspinfo->nspacl,
|
|
||||||
nspinfo->oid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
resetPQExpBuffer(q);
|
resetPQExpBuffer(q);
|
||||||
resetPQExpBuffer(delq);
|
resetPQExpBuffer(delq);
|
||||||
|
|
||||||
appendPQExpBuffer(delq, "DROP SCHEMA %s;\n", qnspname);
|
appendPQExpBuffer(delq, "DROP SCHEMA %s;\n", qnspname);
|
||||||
|
|
||||||
appendPQExpBuffer(q, "CREATE SCHEMA %s;\n", qnspname);
|
appendPQExpBuffer(q, "CREATE SCHEMA %s AUTHORIZATION %s;\n",
|
||||||
|
qnspname, fmtId(nspinfo->usename));
|
||||||
|
|
||||||
ArchiveEntry(fout, nspinfo->oid, nspinfo->nspname,
|
ArchiveEntry(fout, nspinfo->oid, nspinfo->nspname,
|
||||||
NULL,
|
NULL, "", "SCHEMA", NULL,
|
||||||
nspinfo->usename, "SCHEMA", NULL,
|
|
||||||
q->data, delq->data, NULL, NULL, NULL);
|
q->data, delq->data, NULL, NULL, NULL);
|
||||||
|
|
||||||
/* Dump Schema Comments */
|
|
||||||
resetPQExpBuffer(q);
|
|
||||||
appendPQExpBuffer(q, "SCHEMA %s", qnspname);
|
|
||||||
dumpComment(fout, q->data,
|
|
||||||
NULL, nspinfo->usename,
|
|
||||||
nspinfo->oid, "pg_namespace", 0, NULL);
|
|
||||||
|
|
||||||
if (!aclsSkip)
|
|
||||||
dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
|
|
||||||
nspinfo->usename, nspinfo->nspacl,
|
|
||||||
nspinfo->oid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Dump Schema Comments */
|
||||||
|
resetPQExpBuffer(q);
|
||||||
|
appendPQExpBuffer(q, "SCHEMA %s", qnspname);
|
||||||
|
dumpComment(fout, q->data,
|
||||||
|
NULL, nspinfo->usename,
|
||||||
|
nspinfo->oid, "pg_namespace", 0, NULL);
|
||||||
|
|
||||||
|
dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
|
||||||
|
nspinfo->usename, nspinfo->nspacl,
|
||||||
|
nspinfo->oid);
|
||||||
|
|
||||||
free(qnspname);
|
free(qnspname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user