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:
Tom Lane 2003-09-23 23:31:52 +00:00
parent 6767cebc6f
commit a9e9abebd9
2 changed files with 41 additions and 29 deletions

View File

@ -15,7 +15,7 @@
*
*
* 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);
ahprintf(AH, "--\n\n");
/*
* 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;
}

View File

@ -12,7 +12,7 @@
* by PostgreSQL
*
* 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,29 +2879,30 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
/*
* If it's the PUBLIC namespace, don't emit a CREATE SCHEMA record
* for it, since we expect PUBLIC to exist already in the
* destination database. And emit ACL info only if the ACL isn't
* the standard value for PUBLIC.
* destination database. But do emit ACL in case it's not standard,
* 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 (!aclsSkip && strcmp(nspinfo->nspacl, "{=UC}") != 0)
dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
nspinfo->usename, nspinfo->nspacl,
nspinfo->oid);
}
else
if (strcmp(nspinfo->nspname, "public") != 0)
{
resetPQExpBuffer(q);
resetPQExpBuffer(delq);
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,
NULL,
nspinfo->usename, "SCHEMA", NULL,
NULL, "", "SCHEMA", NULL,
q->data, delq->data, NULL, NULL, NULL);
}
/* Dump Schema Comments */
resetPQExpBuffer(q);
@ -2910,11 +2911,9 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
NULL, nspinfo->usename,
nspinfo->oid, "pg_namespace", 0, NULL);
if (!aclsSkip)
dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
nspinfo->usename, nspinfo->nspacl,
nspinfo->oid);
}
free(qnspname);
}