From 40853dd445442e23eec4ffeefa418e53e29e0c23 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 7 Sep 2002 16:14:33 +0000 Subject: [PATCH] Allow pg_dumpall to work with previous releases again. Don't pass the -c 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 | 21 ++++++++++------- doc/src/sgml/ref/pg_dumpall.sgml | 28 +++++++++++----------- src/bin/pg_dump/dumputils.c | 23 +++++++++++++++++- src/bin/pg_dump/dumputils.h | 3 ++- src/bin/pg_dump/pg_backup_db.c | 17 ++++---------- src/bin/pg_dump/pg_dump.c | 35 +++++++--------------------- src/bin/pg_dump/pg_dumpall.c | 40 ++++++++++++++++++++++++-------- 7 files changed, 95 insertions(+), 72 deletions(-) diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 5b5759a1d4..ae1bb7b4ea 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -1,5 +1,5 @@ @@ -289,14 +289,17 @@ PostgreSQL documentation - Ignore version mismatch between pg_dump - and the database server. Since pg_dump - knows a great deal about system catalogs, any given version of - pg_dump 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 - pg_dump then fails, don't - say you weren't warned). + Ignore version mismatch between + pg_dump and the database server. + + + + pg_dump 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 + pg_dump then fails, don't say you + weren't warned). diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml index e6f156dcc6..2439d04086 100644 --- a/doc/src/sgml/ref/pg_dumpall.sgml +++ b/doc/src/sgml/ref/pg_dumpall.sgml @@ -1,5 +1,5 @@ @@ -79,13 +79,12 @@ PostgreSQL documentation - -c, --clean + + - 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. @@ -120,10 +119,11 @@ PostgreSQL documentation - -g, --globals-only + + - Only dump global objects (users and groups), no databases. + Dump only global objects (users and groups), no databases. @@ -135,11 +135,13 @@ PostgreSQL documentation Ignore version mismatch between pg_dumpall and the database server. - Since pg_dumpall knows a great deal - about system catalogs, any given version of - pg_dumpall 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 + + + + pg_dumpall 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 pg_dumpall then fails, don't say you weren't warned). diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index ef71182fcc..259a8c5639 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -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; +} diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h index a34d937a0e..acaff801d8 100644 --- a/src/bin/pg_dump/dumputils.h +++ b/src/bin/pg_dump/dumputils.h @@ -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 */ diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index c3bb6b0e6d..e5572db01d 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -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 diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 6e37343459..3945c3e600 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -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 .\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) { diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 1ff698ef5b..1cf1b628ed 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -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;