Allow pg_dumpall to work with previous releases again. Don't pass the -c
authorPeter Eisentraut <peter_e@gmx.net>
Sat, 7 Sep 2002 16:14:33 +0000 (16:14 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Sat, 7 Sep 2002 16:14:33 +0000 (16:14 +0000)
option down to pg_dump, where it's useless, and clarify the meaning of -c
in the documentation.

doc/src/sgml/ref/pg_dump.sgml
doc/src/sgml/ref/pg_dumpall.sgml
src/bin/pg_dump/dumputils.c
src/bin/pg_dump/dumputils.h
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c

index 5b5759a1d43a1b09a35d8da268901a50bd0995bc..ae1bb7b4ea5797ec45afbf96eb931c14536ec227 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.50 2002/09/06 21:58:36 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.51 2002/09/07 16:14:33 petere Exp $
 PostgreSQL documentation
 -->
 
@@ -289,14 +289,17 @@ PostgreSQL documentation
       <term><option>--ignore-version</></term>
       <listitem>
        <para>
-        Ignore version mismatch between <command>pg_dump</command>
-   and the database server.  Since <command>pg_dump</command>
-   knows a great deal about system catalogs, any given version of
-   <command>pg_dump</command> is only intended to work with
-   the corresponding release of the database server.  Use this option
-   if you need to override the version check (and if
-   <command>pg_dump</command> then fails, don't
-   say you weren't warned).
+        Ignore version mismatch between
+        <application>pg_dump</application> and the database server.
+       </para>
+
+       <para>
+        <application>pg_dump</application> can handle databases from
+        previous releases of PostgreSQL, but very old versions are not
+        supported anymore (currently prior to 7.0).  Use this option
+        if you need to override the version check (and if
+        <application>pg_dump</application> then fails, don't say you
+        weren't warned).
        </para>
       </listitem>
      </varlistentry>
index e6f156dcc6e9f8218b2290d3a82fc931f86970a1..2439d04086610df035d57f7bc2ab897d40ee437e 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.33 2002/09/05 22:05:50 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.34 2002/09/07 16:14:33 petere Exp $
 PostgreSQL documentation
 -->
 
@@ -79,13 +79,12 @@ PostgreSQL documentation
 
     <variablelist>
      <varlistentry>
-      <term>-c, --clean</term>
+      <term><option>-c</option></term>
+      <term><option>--clean</option></term>
       <listitem>
        <para>
-   Include SQL commands to clean (drop) database objects before
-   recreating them.  (This option is fairly useless, since the
-   output script expects to create the databases themselves;
-   they would always be empty upon creation.)
+   Include SQL commands to clean (drop) the databases before
+   recreating them.
        </para>
       </listitem>
      </varlistentry>
@@ -120,10 +119,11 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
-      <term>-g, --globals-only</term>
+      <term><option>-g</option></term>
+      <term><option>--globals-only</option></term>
       <listitem>
        <para>
-   Only dump global objects (users and groups), no databases.
+   Dump only global objects (users and groups), no databases.
        </para>
       </listitem>
      </varlistentry>
@@ -135,11 +135,13 @@ PostgreSQL documentation
        <para>
         Ignore version mismatch between
         <application>pg_dumpall</application> and the database server.
-        Since <application>pg_dumpall</application> knows a great deal
-        about system catalogs, any given version of
-        <application>pg_dumpall</application> is only intended to work
-        with the corresponding release of the database server.  Use
-        this option if you need to override the version check (and if
+       </para>
+
+       <para>
+        <application>pg_dumpall</application> can handle databases
+        from previous releases of PostgreSQL, but very old versions
+        are not supported anymore (currently prior to 7.0).  Use this
+        option if you need to override the version check (and if
         <application>pg_dumpall</application> then fails, don't say
         you weren't warned).
        </para>
index ef71182fcca462bbc31d6c9783ea2c82a6fe6dc7..259a8c5639508be23c91e3b0eefc8442598b311c 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.c,v 1.2 2002/09/04 20:31:34 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.c,v 1.3 2002/09/07 16:14:33 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -131,3 +131,24 @@ appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
    }
    appendPQExpBufferChar(buf, '\'');
 }
+
+
+
+int
+parse_version(const char *versionString)
+{
+   int         cnt;
+   int         vmaj,
+               vmin,
+               vrev;
+
+   cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev);
+
+   if (cnt < 2)
+       return -1;
+
+   if (cnt == 2)
+       vrev = 0;
+
+   return (100 * vmaj + vmin) * 100 + vrev;
+}
index a34d937a0eb69e381cbf36c25c62df109c84640d..acaff801d880f9a09c80f8421d1fdb8382b6c2c5 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.h,v 1.3 2002/09/04 20:31:34 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/dumputils.h,v 1.4 2002/09/07 16:14:33 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,5 +22,6 @@ extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
 
 extern const char *fmtId(const char *identifier);
 extern void appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll);
+extern int parse_version(const char *versionString);
 
 #endif   /* DUMPUTILS_H */
index c3bb6b0e6dffdb6e1eb39d7dfddd63867d9f60e4..e5572db01d7700addcb5acd359a5bfc53382892c 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.40 2002/09/04 20:31:34 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.41 2002/09/07 16:14:33 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -41,20 +41,13 @@ static char *_sendCopyLine(ArchiveHandle *AH, char *qry, char *eos);
 static int
 _parse_version(ArchiveHandle *AH, const char *versionString)
 {
-   int         cnt;
-   int         vmaj,
-               vmin,
-               vrev;
+   int         v;
 
-   cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev);
-
-   if (cnt < 2)
+   v = parse_version(versionString);
+   if (v < 0)
        die_horribly(AH, modulename, "unable to parse version string \"%s\"\n", versionString);
 
-   if (cnt == 2)
-       vrev = 0;
-
-   return (100 * vmaj + vmin) * 100 + vrev;
+   return v;
 }
 
 static void
index 6e373434594991baae9b75dd8ffb2c538ef2aede..3945c3e600585b29626889353740b05cc46f4aa7 100644 (file)
@@ -22,7 +22,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.297 2002/09/04 20:31:34 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.298 2002/09/07 16:14:33 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -75,7 +75,6 @@ typedef struct _dumpContext
 } DumpContext;
 
 static void help(const char *progname);
-static int parse_version(const char *versionString);
 static NamespaceInfo *findNamespace(const char *nsoid, const char *objoid);
 static void dumpClasses(const TableInfo *tblinfo, const int numTables,
            Archive *fout, const bool oids);
@@ -535,12 +534,18 @@ main(int argc, char **argv)
    /* Let the archiver know how noisy to be */
    g_fout->verbose = g_verbose;
 
+   g_fout->minRemoteVersion = 70000;   /* we can handle back to 7.0 */
+   g_fout->maxRemoteVersion = parse_version(PG_VERSION);
+   if (g_fout->maxRemoteVersion < 0)
+   {
+       write_msg(NULL, "unable to parse version string \"%s\"\n", PG_VERSION);
+       exit(1);
+   }
+
    /*
     * Open the database using the Archiver, so it knows about it. Errors
     * mean death.
     */
-   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);
 
    /*
@@ -726,28 +731,6 @@ help(const char *progname)
    printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
 }
 
-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;
-}
-
 void
 exit_nicely(void)
 {
index 1ff698ef5b97c4b4137c44edbd0c2d6ed67c4af4..1cf1b628ed76eb2137374517eb7d5867e2ed5200 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.6 2002/09/04 20:31:35 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.7 2002/09/07 16:14:33 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -56,6 +56,7 @@ char     *pgdumploc;
 PQExpBuffer pgdumpopts;
 bool       output_clean = false;
 bool       verbose = false;
+int            server_version;
 
 
 
@@ -127,7 +128,6 @@ main(int argc, char *argv[])
        {
            case 'c':
                output_clean = true;
-               appendPQExpBuffer(pgdumpopts, " -c");
                break;
 
            case 'd':
@@ -217,10 +217,10 @@ help(void)
 
    printf(_("Options:\n"));
 #ifdef HAVE_GETOPT_LONG
-   printf(_("  -c, --clean              clean (drop) schema prior to create\n"));
+   printf(_("  -c, --clean              clean (drop) databases prior to create\n"));
    printf(_("  -d, --inserts            dump data as INSERT, rather than COPY, commands\n"));
    printf(_("  -D, --column-inserts     dump data as INSERT commands with column names\n"));
-   printf(_("  -g, --globals-only       only dump global objects, no databases\n"));
+   printf(_("  -g, --globals-only       dump only global objects, no databases\n"));
    printf(_("  -h, --host=HOSTNAME      database server host name\n"));
    printf(_("  -i, --ignore-version     proceed even when server version mismatches\n"
             "                           pg_dumpall version\n"));
@@ -230,10 +230,10 @@ help(void)
    printf(_("  -v, --verbose            verbose mode\n"));
    printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
 #else                          /* not HAVE_GETOPT_LONG */
-   printf(_("  -c                       clean (drop) schema prior to create\n"));
+   printf(_("  -c                       clean (drop) databases prior to create\n"));
    printf(_("  -d                       dump data as INSERT, rather than COPY, commands\n"));
    printf(_("  -D                       dump data as INSERT commands with column names\n"));
-   printf(_("  -g                       only dump global objects, no databases\n"));
+   printf(_("  -g                       dump only global objects, no databases\n"));
    printf(_("  -h HOSTNAME              database server host name\n"));
    printf(_("  -i                       proceed even when server version mismatches\n"
             "                           pg_dumpall version\n"));
@@ -301,7 +301,8 @@ dumpUsers(PGconn *conn)
        printf("%s", buf->data);
        destroyPQExpBuffer(buf);
 
-       dumpUserConfig(conn, username);
+       if (server_version >= 70300)
+           dumpUserConfig(conn, username);
    }
 
    PQclear(res);
@@ -431,7 +432,8 @@ dumpCreateDB(PGconn *conn)
        printf("%s", buf->data);
        destroyPQExpBuffer(buf);
 
-       dumpDatabaseConfig(conn, dbname);
+       if (server_version >= 70300)
+           dumpDatabaseConfig(conn, dbname);
    }
 
    PQclear(res);
@@ -609,6 +611,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
    PGconn     *conn;
    char       *password = NULL;
    bool        need_pass = false;
+   PGresult   *res;
 
    if (require_password)
        password = simple_prompt("Password: ", 100, false);
@@ -626,7 +629,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
        {
            fprintf(stderr, _("%s: could not connect to database %s\n"),
                    progname, dbname);
-           exit(0);
+           exit(1);
        }
 
        if (PQstatus(conn) == CONNECTION_BAD &&
@@ -649,7 +652,24 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
    {
        fprintf(stderr, _("%s: could not connect to database %s: %s\n"),
                progname, dbname, PQerrorMessage(conn));
-       exit(0);
+       exit(1);
+   }
+
+   res = executeQuery(conn, "SELECT version();");
+   if (PQntuples(res) != 1)
+   {
+       fprintf(stderr, _("%s: could not get server version\n"), progname);
+       exit(1);
+   }
+   else
+   {
+       char *val = PQgetvalue(res, 0, 0);
+       server_version = parse_version(val + strcspn(val, "0123456789"));
+       if (server_version < 0)
+       {
+           fprintf(stderr, _("%s: could not parse server version \"%s\"\n"), progname, val);
+           exit(1);
+       }
    }
 
    return conn;