]> granicus.if.org Git - postgresql/commitdiff
Issue CREATE SCHEMA as the originally connecting user, with an
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Sep 2003 23:31:52 +0000 (23:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Sep 2003 23:31:52 +0000 (23:31 +0000)
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.

src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c

index cf39972457f53112b0fa04a2532c23abc3bdd862..a2181ce7724cff94a873b54b63b54d5ebea0a32f 100644 (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");
 
-       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;
 }
index 501cf59f1e47d6def0558ceb70890e63bb079d41..8e77850a51f1670069f70a0f3abbb7e1dea7e9d2 100644 (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,42 +2879,41 @@ 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);
-                       appendPQExpBuffer(q, "SCHEMA %s", qnspname);
-                       dumpComment(fout, q->data,
-                                               NULL, nspinfo->usename,
-                                               nspinfo->oid, "pg_namespace", 0, 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);
-               }
+               dumpACL(fout, "SCHEMA", qnspname, nspinfo->nspname, NULL,
+                               nspinfo->usename, nspinfo->nspacl,
+                               nspinfo->oid);
 
                free(qnspname);
        }