]> granicus.if.org Git - postgresql/commitdiff
Make pg_dump handle the new privileges.
authorPeter Eisentraut <peter_e@gmx.net>
Sun, 12 Aug 2001 19:02:39 +0000 (19:02 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Sun, 12 Aug 2001 19:02:39 +0000 (19:02 +0000)
Don't hardcode the maximum accepted server version, use PG_VERSION instead.
Install a notice processor so notices are handled like error messages.
Word smithing.

doc/src/sgml/ref/pg_dump.sgml
doc/src/sgml/ref/pg_restore.sgml
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_restore.c

index 14f2f9e497ac7b84fe8cf2b02276b02f6e68b875..2eec491cd42ee8f294f0274caa53a0b67fcf25a6 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.33 2001/05/17 21:50:18 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.34 2001/08/12 19:02:39 petere Exp $
 Postgres documentation
 -->
 
@@ -121,7 +121,7 @@ Postgres documentation
       <term>--data-only</term>
       <listitem>
        <para>
-       Dump only the data, not the schema (definitions).
+       Dump only the data, not the schema (data definitions).
        </para>
       </listitem>
      </varlistentry>
@@ -171,11 +171,15 @@ Postgres documentation
 
      <varlistentry>
       <term>-D</term>
+      <term>--column-inserts</term>
       <term>--attribute-inserts</term>
       <listitem>
        <para>
        Dump data as <command>INSERT</command> commands with explicit
-       column names.  This will make restoration very slow.
+       column names (<literal>INSERT INTO
+       <replaceable>table</replaceable>
+       (<replaceable>column</replaceable>, ...) VALUES
+       ...</literal>).  This will make restoration very slow.
        </para>
       </listitem>
      </varlistentry>
@@ -320,7 +324,7 @@ Postgres documentation
       <term>--schema-only</term>
       <listitem>
        <para>
-       Dump only the schema (definitions), no data.
+       Dump only the schema (data definitions), no data.
        </para>
       </listitem>
      </varlistentry>
@@ -358,10 +362,12 @@ Postgres documentation
 
      <varlistentry>
       <term>-x</term>
+      <term>--no-privileges</term>
       <term>--no-acl</term>
       <listitem>
        <para>
-       Prevent dumping of ACLs (grant/revoke commands) and table ownership information.
+       Prevent dumping of access privileges (grant/revoke commands)
+       and table ownership information.
        </para>
       </listitem>
      </varlistentry>
@@ -467,24 +473,6 @@ connectDBStart() -- connect() failed: No such file or directory
     </msgexplan>
    </msgentry>
 
-   <msgentry>
-    <msg>
-     <msgmain>
-      <msgtext>
-<screen><computeroutput>
-dumpSequence(<replaceable class="parameter">table</replaceable>): SELECT failed
-</computeroutput></screen>
-      </msgtext>
-     </msgmain>
-    </msg>
-
-    <msgexplan>
-       <para>
-       You do not have permission to read the database.
-       Contact your <productname>Postgres</productname> site administrator.
-       </para>
-    </msgexplan>
-   </msgentry>
   </msgset>
 
    <note>
@@ -503,9 +491,6 @@ dumpSequence(<replaceable class="parameter">table</replaceable>): SELECT failed
   <title>Notes</title>
   <para>
    <command>pg_dump</command> has a few limitations.
-   The limitations mostly stem from
-   difficulty in extracting certain meta-information from the system
-   catalogs.
 
    <itemizedlist>
     <listitem>
index e30f42421887a863ebc2ede2b9bb450019c0c0cf..0acb3fb1512503e970a7505c5ea354f1009b5f43 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.12 2001/05/17 21:50:18 petere Exp $ -->
+<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.13 2001/08/12 19:02:39 petere Exp $ -->
 
 <refentry id="APP-PGRESTORE">
  <docinfo>
 
      <varlistentry>
       <term>-x</term>
+      <term>--no-privileges</term>
       <term>--no-acl</term>
       <listitem>
        <para>
-       Prevent restoration of ACLs (grant/revoke commands).
+       Prevent restoration of access privileges (grant/revoke commands).
        </para>
       </listitem>
      </varlistentry>
index eea98ca7e5caaf084876be6fb0b93a499df3f70d..514f132c929b01b0286f0d9a3bda7cf5b2172b30 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *             $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.29 2001/07/03 20:21:48 petere Exp $
+ *             $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.30 2001/08/12 19:02:39 petere Exp $
  *
  * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
  *
@@ -777,7 +777,7 @@ StartRestoreBlob(ArchiveHandle *AH, Oid oid)
        if (!AH->createdBlobXref)
        {
                if (!AH->connection)
-                       die_horribly(AH, modulename, "cannot restore BLOBs without a database connection");
+                       die_horribly(AH, modulename, "cannot restore BLOBs without a database connection\n");
 
                CreateBlobXrefTable(AH);
                AH->createdBlobXref = 1;
index fc5864bc693bbff3d5259b13df786f1bfbef0af1..f08a0d3085fb591084a89e02d75693f239926a0d 100644 (file)
@@ -5,7 +5,7 @@
  *     Implements the basic DB functions used by the archiver.
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.22 2001/08/03 19:43:05 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.23 2001/08/12 19:02:39 petere Exp $
  *
  * NOTES
  *
@@ -42,6 +42,7 @@ static const char *modulename = gettext_noop("archiver (db)");
 static void _check_database_version(ArchiveHandle *AH, bool ignoreVersion);
 static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, char *newUser);
 static int     _executeSqlCommand(ArchiveHandle *AH, PGconn *conn, PQExpBuffer qry, char *desc);
+static void notice_processor(void *arg, const char *message);
 
 
 /*
@@ -164,7 +165,7 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
        if (myversion != remoteversion 
                && (remoteversion < AH->public.minRemoteVersion || remoteversion > AH->public.maxRemoteVersion) )
        {
-               write_msg(NULL, "server version: %s, %s version: %s\n",
+               write_msg(NULL, "server version: %s; %s version: %s\n",
                                  remoteversion_str, progname, PG_VERSION);
                if (ignoreVersion)
                        write_msg(NULL, "proceeding despite version mismatch\n");
@@ -325,6 +326,8 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, char *requser)
        if (password)
                free(password);
 
+       PQsetNoticeProcessor(newConn, notice_processor, NULL);
+
        return newConn;
 }
 
@@ -416,6 +419,8 @@ ConnectDatabase(Archive *AHX,
        /* check for version mismatch */
        _check_database_version(AH, ignoreVersion);
 
+       PQsetNoticeProcessor(AH->connection, notice_processor, NULL);
+
        /*
         * AH->currUser = PQuser(AH->connection);
         *
@@ -426,6 +431,13 @@ ConnectDatabase(Archive *AHX,
        return AH->connection;
 }
 
+
+static void notice_processor(void *arg, const char *message)
+{
+       write_msg(NULL, "%s", message);
+}
+
+
 /* Public interface */
 /* Convenience function to send a query. Monitors result to handle COPY statements */
 int
index 958ad3298507f13a7008b320f981884d5fb9ed25..7f9363211a8b010f9096556294c54575c96aea73 100644 (file)
  *               indexes
  *               aggregates
  *               operators
- *               ACL - grant/revoke
+ *               privileges
  *
  * the output script is SQL that is understood by PostgreSQL
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.220 2001/08/10 22:50:09 tgl Exp $
- *
- * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
- *
- *      Applied 'insert string' patch from "Marc G. Fournier" <scrappy@ki.net>
- *      Added '-t table' option
- *      Added '-a' option
- *      Added '-da' option
- *
- * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
- *
- *      - Fixed dumpTable output to output lengths for char and varchar types!
- *      - Added single. quote to twin single quote expansion for 'insert' string
- *        mode.
- *
- * Modifications - 7/26/96 - asussman@vidya.com
- *
- *      - Fixed ouput lengths for char and varchar type where the length is variable (-1)
- *
- * Modifications - 6/1/97 - igor@sba.miami.edu
- * - Added functions to free allocated memory used for retrieving
- *      indexes,tables,inheritance,types,functions and aggregates.
- *      No more leaks reported by Purify.
- *
- *
- * Modifications - 1/26/98 - pjlobo@euitt.upm.es
- *              - Added support for password authentication
- *
- * Modifications - 28-Jun-2000 - Philip Warner pjw@rhyme.com.au
- *              - Used custom IO routines to allow for more
- *                output formats and simple rearrangement of order.
- *              - Discouraged operations more appropriate to the 'restore'
- *                operation. (eg. -c "clear schema" - now always dumps
- *                commands, but pg_restore can be told not to output them).
- *              - Added RI warnings to the 'as insert strings' output mode
- *              - Added a small number of comments
- *              - Added a -Z option for compression level on compressed formats
- *              - Restored '-f' in usage output
- *
- *
- * Modifications - 17-Jul-2000 - Philip Warner pjw@rhyme.com.au
- *              - Support for BLOB output.
- *              - Sort archive by OID, put some items at end (out of OID order)
- *
- * Modifications - 28-Jul-2000 - pjw@rhyme.com.au (1.45)
- *
- *             Added --create, --no-owner, --superuser, --no-reconnect (pg_dump & pg_restore)
- *             Added code to dump 'Create Schema' statement (pg_dump)
- *             Don't bother to disable/enable triggers if we don't have a superuser (pg_restore)
- *             Cleaned up code for reconnecting to database.
- *             Force a reconnect as superuser before enabling/disabling triggers.
- *
- * Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
- *             Added & Removed --throttle (pg_dump)
- *             Fixed minor bug in language dumping code: expbuffres were not being reset.
- *             Fixed version number initialization in _allocAH (pg_backup_archiver.c)
- *
- * Modifications - 14-Sep-2000 - pjw@rhyme.com.au
- *             Use symbols for tests on relkind (ie. use RELKIND_VIEW, not 'v')
- *             Support for relkind = RELKIND_VIEW.
- *             Fix bug in support for -b option (== --blobs).
- *             Dump views as views (using 'create view').
- *             Remove 'isViewRule' since we check the relkind when getting tables.
- *             Now uses temp table 'pgdump_oid' rather than 'pg_dump_oid' (errors otherwise).
- *
- * Modifications - 02-Oct-2000 - pjw@rhyme.com.au
- *
- *       - Be more paranoid when getting views: call get_viewdef in separate statement
- *             so we can be more informative in error messages.
- *       - Support for 'isstrict' procedure attribute.
- *       - Disable --blobs and --table since (a) it's a pain to get ONLY the blobs for the
- *             table with the currently implementation, and (b) it's not clear how to restore
- *             a partial BLOB backup (given the current OID-based BLOB implementation).
- *
- * Modifications - 04-Jan-2001 - pjw@rhyme.com.au
- *
- *       - Check ntuples == 1 for various SELECT statements.
- *       - Fix handling of --tables=* (multiple tables never worked properly, AFAICT)
- *
- * Modifications - 13-Feb-2001 - pjw@rhyme.com.au
- *
- *       - Fix help output: replace 'f' with 't' and change desc.
- *       - Add extra arg to formatStringLiteral to specify how to handle LF & TAB.
- *             I opted for encoding them except in procedure bodies.
- *       - Dump relevant parts of sequences only when doing schemaOnly & dataOnly
- *       - Prevent double-dumping of sequences when dataOnly.
- *
- * Modifications - 19-Mar-2001 - pjw@rhyme.com.au
- *
- *       - Remove fmtId calls for all ArchiveEntry name fields. This fixes
- *             quoting problems in trigger enable/disable code for mixed case
- *             table names, and avoids commands like 'pg_restore -t '"TblA"''
- *
- * Modifications - 31-Mar-2001 - pjw@rhyme.com.au
- *
- *       - Dump dependency information in dumpType. This is necessary
- *             because placeholder types will have an OID less than the
- *             OID of the type functions, but type must be created after
- *             the functions.
- *
- * Modifications - 4-Apr-2001 - pjw@rhyme.com.au
- *
- *       - Don't dump CHECK constraints with same source and names both
- *             starting with '$'.
- *
- * Modifications - 10-May-2001 - pjw@rhyme.com.au
- *
- *       - Don't dump COMMENTs in data-only dumps
- *       - Fix view dumping SQL for V7.0
- *       - Fix bug when getting view oid with long view names
+ *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.221 2001/08/12 19:02:39 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -200,7 +91,7 @@ static Oid   findLastBuiltinOid_V70(void);
 static void setMaxOid(Archive *fout);
 
 static void AddAcl(char *aclbuf, const char *keyword);
-static char *GetPrivileges(const char *s);
+static char *GetPrivileges(Archive *AH, const char *s);
 
 static int     dumpBlobs(Archive *AH, char *, void *);
 static int     dumpDatabase(Archive *AH);
@@ -254,7 +145,7 @@ help(const char *progname)
                "  -c, --clean              clean (drop) schema prior to create\n"
                "  -C, --create             include commands to create database in dump\n"
                "  -d, --inserts            dump data as INSERT, rather than COPY, commands\n"
-               "  -D, --attribute-inserts  dump data as INSERT commands with column names\n"
+               "  -D, --column-inserts     dump data as INSERT commands with column names\n"
                "  -f, --file=FILENAME      output file name\n"
                "  -F, --format {c|t|p}     output file format (custom, tar, plain text)\n"
                "  -h, --host=HOSTNAME      database server host name\n"
@@ -275,7 +166,7 @@ help(const char *progname)
                "  -U, --username=NAME      connect as specified database user\n"
                "  -v, --verbose            verbose mode\n"
                "  -W, --password           force password prompt (should happen automatically)\n"
-               "  -x, --no-acl             do not dump privileges (grant/revoke)\n"
+               "  -x, --no-privileges      do not dump privileges (grant/revoke)\n"
                "  -Z, --compress {0-9}     compression level for compressed formats\n"
                ));
 #else
@@ -690,6 +581,30 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
        }
 }
 
+
+
+static int
+parse_version(const char* versionString)
+{
+       int                     cnt;
+       int                     vmaj, vmin, vrev;
+
+       cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev);
+
+       if (cnt < 2)
+       {
+               write_msg(NULL, "unable to parse version string \"%s\"\n", versionString);
+               exit(1);
+       }
+
+       if (cnt == 2)
+               vrev = 0;
+
+       return (100 * vmaj + vmin) * 100 + vrev;
+}
+
+
+
 int
 main(int argc, char **argv)
 {
@@ -727,6 +642,7 @@ main(int argc, char **argv)
                {"format", required_argument, NULL, 'F'},
                {"inserts", no_argument, NULL, 'd'},
                {"attribute-inserts", no_argument, NULL, 'D'},
+               {"column-inserts", no_argument, NULL, 'D'},
                {"host", required_argument, NULL, 'h'},
                {"ignore-version", no_argument, NULL, 'i'},
                {"no-reconnect", no_argument, NULL, 'R'},
@@ -741,6 +657,7 @@ main(int argc, char **argv)
                {"password", no_argument, NULL, 'W'},
                {"username", required_argument, NULL, 'U'},
                {"verbose", no_argument, NULL, 'v'},
+               {"no-privileges", no_argument, NULL, 'x'},
                {"no-acl", no_argument, NULL, 'x'},
                {"compress", required_argument, NULL, 'Z'},
                {"help", no_argument, NULL, '?'},
@@ -1041,10 +958,10 @@ main(int argc, char **argv)
 
        /*
         * Open the database using the Archiver, so it knows about it. Errors
-        * mean death. Accept 7.0 & 7.1 database versions.
+        * mean death.
         */
-       g_fout->minRemoteVersion = 70000;
-       g_fout->maxRemoteVersion = 70199;
+       g_fout->minRemoteVersion = 70000; /* we can handle back to 7.0 */
+       g_fout->maxRemoteVersion = parse_version(PG_VERSION);
        g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, username, force_password, ignore_version);
 
        /*
@@ -3856,7 +3773,7 @@ AddAcl(char *aclbuf, const char *keyword)
  * comma delimited string of SELECT,INSERT,UPDATE,DELETE,RULE
  */
 static char *
-GetPrivileges(const char *s)
+GetPrivileges(Archive *AH, const char *s)
 {
        char            aclbuf[100];
 
@@ -3865,18 +3782,28 @@ GetPrivileges(const char *s)
        if (strchr(s, 'a'))
                AddAcl(aclbuf, "INSERT");
 
-       if (strchr(s, 'w'))
-               AddAcl(aclbuf, "UPDATE,DELETE");
-
        if (strchr(s, 'r'))
                AddAcl(aclbuf, "SELECT");
 
        if (strchr(s, 'R'))
                AddAcl(aclbuf, "RULE");
 
-       /* Special-case when they're all there */
-       if (strcmp(aclbuf, "INSERT,UPDATE,DELETE,SELECT,RULE") == 0)
-               return strdup("ALL");
+       if (AH->remoteVersion >= 70200)
+       {
+               if (strchr(s, 'w'))
+                       AddAcl(aclbuf, "UPDATE");
+               if (strchr(s, 'd'))
+                       AddAcl(aclbuf, "DELETE");
+               if (strchr(s, 'x'))
+                       AddAcl(aclbuf, "REFERENCES");
+               if (strchr(s, 't'))
+                       AddAcl(aclbuf, "TRIGGER");
+       }
+       else
+       {
+               if (strchr(s, 'w'))
+                       AddAcl(aclbuf, "UPDATE,DELETE");
+       }
 
        return strdup(aclbuf);
 }
@@ -3963,7 +3890,7 @@ dumpACL(Archive *fout, TableInfo tbinfo)
                 * Parse the privileges (right-hand side).      Skip if there are
                 * none.
                 */
-               priv = GetPrivileges(eqpos + 1);
+               priv = GetPrivileges(fout, eqpos + 1);
                if (*priv)
                {
                        sprintf(tmp, "GRANT %s on %s to ",
index 50eac5c30421960ea82ad3ce36ad356353dde9c1..ced4f34c87cde2ecca01a230fc2d25d1d45894f9 100644 (file)
@@ -34,7 +34,7 @@
  *
  *
  * IDENTIFICATION
- *             $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.22 2001/07/03 20:21:50 petere Exp $
+ *             $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.23 2001/08/12 19:02:39 petere Exp $
  *
  * Modifications - 28-Jun-2000 - pjw@rhyme.com.au
  *
@@ -89,11 +89,12 @@ struct option cmdopts[] = {
        {"dbname", 1, NULL, 'd'},
        {"file", 1, NULL, 'f'},
        {"format", 1, NULL, 'F'},
-       {"function", 2, NULL, 'P'},
+       {"function", 1, NULL, 'P'},
        {"host", 1, NULL, 'h'},
        {"ignore-version", 0, NULL, 'i'},
-       {"index", 2, NULL, 'I'},
+       {"index", 1, NULL, 'I'},
        {"list", 0, NULL, 'l'},
+       {"no-privileges", 0, NULL, 'x'},
        {"no-acl", 0, NULL, 'x'},
        {"no-owner", 0, NULL, 'O'},
        {"no-reconnect", 0, NULL, 'R'},
@@ -104,8 +105,8 @@ struct option cmdopts[] = {
        {"rearrange", 0, NULL, 'r'},
        {"schema-only", 0, NULL, 's'},
        {"superuser", 1, NULL, 'S'},
-       {"table", 2, NULL, 't'},
-       {"trigger", 2, NULL, 'T'},
+       {"table", 1, NULL, 't'},
+       {"trigger", 1, NULL, 'T'},
        {"use-list", 1, NULL, 'L'},
        {"username", 1, NULL, 'U'},
        {"verbose", 0, NULL, 'v'},
@@ -359,7 +360,7 @@ usage(const char *progname)
                "  -f, --file=FILENAME      script output file name\n"
                "  -F, --format {c|f}       specify backup file format\n"
                "  -h, --host HOSTNAME      server host name\n"
-               "  -i, --index[=NAME]       restore indexes or named index\n"
+               "  -i, --index=NAME         restore indexes or named index\n"
                "  -l, --list               dump summarized TOC for this file\n"
                "  -L, --use-list=FILENAME  use specified table of contents for ordering\n"
                "                           output from this file\n"
@@ -368,18 +369,18 @@ usage(const char *progname)
                "  -O, --no-owner           do not reconnect to database to match\n"
                "                           object owner\n"
                "  -p, --port PORT          server port number\n"
-               "  -P, --function[=NAME]    restore functions or named function\n"
+               "  -P, --function=NAME      restore functions or named function\n"
                "  -r, --rearrange          rearrange output to put indexes etc. at end\n"
                "  -R, --no-reconnect       disallow ALL reconnections to the database\n"
                "  -s, --schema-only        restore only the schema, no data\n"
                "  -S, --superuser=NAME     specify the superuser user name to use for\n"
                "                           disabling triggers\n"
-               "  -t, --table[=TABLE]      restore this table only\n"
-               "  -T, --trigger[=NAME]     restore triggers or named trigger\n"
+               "  -t, --table=TABLE        restore this table only\n"
+               "  -T, --trigger=NAME       restore triggers or named trigger\n"
                "  -U, --username=NAME      connect as specified database user\n"
                "  -v, --verbose            verbose\n"
                "  -W, --password           force password prompt (should happen automatically)\n"
-               "  -x, --no-acl             skip dumping of ACLs (grant/revoke)\n"
+               "  -x, --no-privileges      skip dumping of access privileges (grant/revoke)\n"
                ));
 
 #else /* not HAVE_GETOPT_LONG */