Commit 40853dd4 authored by Peter Eisentraut's avatar Peter Eisentraut

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.
parent 123baf83
<!-- <!--
$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 PostgreSQL documentation
--> -->
...@@ -289,14 +289,17 @@ PostgreSQL documentation ...@@ -289,14 +289,17 @@ PostgreSQL documentation
<term><option>--ignore-version</></term> <term><option>--ignore-version</></term>
<listitem> <listitem>
<para> <para>
Ignore version mismatch between <command>pg_dump</command> Ignore version mismatch between
and the database server. Since <command>pg_dump</command> <application>pg_dump</application> and the database server.
knows a great deal about system catalogs, any given version of </para>
<command>pg_dump</command> is only intended to work with
the corresponding release of the database server. Use this option <para>
if you need to override the version check (and if <application>pg_dump</application> can handle databases from
<command>pg_dump</command> then fails, don't previous releases of PostgreSQL, but very old versions are not
say you weren't warned). 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> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
<!-- <!--
$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 PostgreSQL documentation
--> -->
...@@ -79,13 +79,12 @@ PostgreSQL documentation ...@@ -79,13 +79,12 @@ PostgreSQL documentation
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>-c, --clean</term> <term><option>-c</option></term>
<term><option>--clean</option></term>
<listitem> <listitem>
<para> <para>
Include SQL commands to clean (drop) database objects before Include SQL commands to clean (drop) the databases before
recreating them. (This option is fairly useless, since the recreating them.
output script expects to create the databases themselves;
they would always be empty upon creation.)
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -120,10 +119,11 @@ PostgreSQL documentation ...@@ -120,10 +119,11 @@ PostgreSQL documentation
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>-g, --globals-only</term> <term><option>-g</option></term>
<term><option>--globals-only</option></term>
<listitem> <listitem>
<para> <para>
Only dump global objects (users and groups), no databases. Dump only global objects (users and groups), no databases.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -135,11 +135,13 @@ PostgreSQL documentation ...@@ -135,11 +135,13 @@ PostgreSQL documentation
<para> <para>
Ignore version mismatch between Ignore version mismatch between
<application>pg_dumpall</application> and the database server. <application>pg_dumpall</application> and the database server.
Since <application>pg_dumpall</application> knows a great deal </para>
about system catalogs, any given version of
<application>pg_dumpall</application> is only intended to work <para>
with the corresponding release of the database server. Use <application>pg_dumpall</application> can handle databases
this option if you need to override the version check (and if 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 <application>pg_dumpall</application> then fails, don't say
you weren't warned). you weren't warned).
</para> </para>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * 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) ...@@ -131,3 +131,24 @@ appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
} }
appendPQExpBufferChar(buf, '\''); 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;
}
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * 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); ...@@ -22,5 +22,6 @@ extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
extern const char *fmtId(const char *identifier); extern const char *fmtId(const char *identifier);
extern void appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll); extern void appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll);
extern int parse_version(const char *versionString);
#endif /* DUMPUTILS_H */ #endif /* DUMPUTILS_H */
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver. * Implements the basic DB functions used by the archiver.
* *
* IDENTIFICATION * 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); ...@@ -41,20 +41,13 @@ static char *_sendCopyLine(ArchiveHandle *AH, char *qry, char *eos);
static int static int
_parse_version(ArchiveHandle *AH, const char *versionString) _parse_version(ArchiveHandle *AH, const char *versionString)
{ {
int cnt; int v;
int vmaj,
vmin,
vrev;
cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev); v = parse_version(versionString);
if (v < 0)
if (cnt < 2)
die_horribly(AH, modulename, "unable to parse version string \"%s\"\n", versionString); die_horribly(AH, modulename, "unable to parse version string \"%s\"\n", versionString);
if (cnt == 2) return v;
vrev = 0;
return (100 * vmaj + vmin) * 100 + vrev;
} }
static void static void
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * 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 ...@@ -75,7 +75,6 @@ typedef struct _dumpContext
} DumpContext; } DumpContext;
static void help(const char *progname); static void help(const char *progname);
static int parse_version(const char *versionString);
static NamespaceInfo *findNamespace(const char *nsoid, const char *objoid); static NamespaceInfo *findNamespace(const char *nsoid, const char *objoid);
static void dumpClasses(const TableInfo *tblinfo, const int numTables, static void dumpClasses(const TableInfo *tblinfo, const int numTables,
Archive *fout, const bool oids); Archive *fout, const bool oids);
...@@ -535,12 +534,18 @@ main(int argc, char **argv) ...@@ -535,12 +534,18 @@ main(int argc, char **argv)
/* Let the archiver know how noisy to be */ /* Let the archiver know how noisy to be */
g_fout->verbose = g_verbose; 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 * Open the database using the Archiver, so it knows about it. Errors
* mean death. * 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); g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, username, force_password, ignore_version);
/* /*
...@@ -726,28 +731,6 @@ help(const char *progname) ...@@ -726,28 +731,6 @@ help(const char *progname)
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n")); 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 void
exit_nicely(void) exit_nicely(void)
{ {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * 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; ...@@ -56,6 +56,7 @@ char *pgdumploc;
PQExpBuffer pgdumpopts; PQExpBuffer pgdumpopts;
bool output_clean = false; bool output_clean = false;
bool verbose = false; bool verbose = false;
int server_version;
...@@ -127,7 +128,6 @@ main(int argc, char *argv[]) ...@@ -127,7 +128,6 @@ main(int argc, char *argv[])
{ {
case 'c': case 'c':
output_clean = true; output_clean = true;
appendPQExpBuffer(pgdumpopts, " -c");
break; break;
case 'd': case 'd':
...@@ -217,10 +217,10 @@ help(void) ...@@ -217,10 +217,10 @@ help(void)
printf(_("Options:\n")); printf(_("Options:\n"));
#ifdef HAVE_GETOPT_LONG #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, --inserts dump data as INSERT, rather than COPY, commands\n"));
printf(_(" -D, --column-inserts dump data as INSERT commands with column names\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(_(" -h, --host=HOSTNAME database server host name\n"));
printf(_(" -i, --ignore-version proceed even when server version mismatches\n" printf(_(" -i, --ignore-version proceed even when server version mismatches\n"
" pg_dumpall version\n")); " pg_dumpall version\n"));
...@@ -230,10 +230,10 @@ help(void) ...@@ -230,10 +230,10 @@ help(void)
printf(_(" -v, --verbose verbose mode\n")); printf(_(" -v, --verbose verbose mode\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\n")); printf(_(" -W, --password force password prompt (should happen automatically)\n"));
#else /* not HAVE_GETOPT_LONG */ #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, rather than COPY, commands\n"));
printf(_(" -D dump data as INSERT commands with column names\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(_(" -h HOSTNAME database server host name\n"));
printf(_(" -i proceed even when server version mismatches\n" printf(_(" -i proceed even when server version mismatches\n"
" pg_dumpall version\n")); " pg_dumpall version\n"));
...@@ -301,7 +301,8 @@ dumpUsers(PGconn *conn) ...@@ -301,7 +301,8 @@ dumpUsers(PGconn *conn)
printf("%s", buf->data); printf("%s", buf->data);
destroyPQExpBuffer(buf); destroyPQExpBuffer(buf);
dumpUserConfig(conn, username); if (server_version >= 70300)
dumpUserConfig(conn, username);
} }
PQclear(res); PQclear(res);
...@@ -431,7 +432,8 @@ dumpCreateDB(PGconn *conn) ...@@ -431,7 +432,8 @@ dumpCreateDB(PGconn *conn)
printf("%s", buf->data); printf("%s", buf->data);
destroyPQExpBuffer(buf); destroyPQExpBuffer(buf);
dumpDatabaseConfig(conn, dbname); if (server_version >= 70300)
dumpDatabaseConfig(conn, dbname);
} }
PQclear(res); PQclear(res);
...@@ -609,6 +611,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, ...@@ -609,6 +611,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
PGconn *conn; PGconn *conn;
char *password = NULL; char *password = NULL;
bool need_pass = false; bool need_pass = false;
PGresult *res;
if (require_password) if (require_password)
password = simple_prompt("Password: ", 100, false); password = simple_prompt("Password: ", 100, false);
...@@ -626,7 +629,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, ...@@ -626,7 +629,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
{ {
fprintf(stderr, _("%s: could not connect to database %s\n"), fprintf(stderr, _("%s: could not connect to database %s\n"),
progname, dbname); progname, dbname);
exit(0); exit(1);
} }
if (PQstatus(conn) == CONNECTION_BAD && if (PQstatus(conn) == CONNECTION_BAD &&
...@@ -649,7 +652,24 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, ...@@ -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"), fprintf(stderr, _("%s: could not connect to database %s: %s\n"),
progname, dbname, PQerrorMessage(conn)); 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; return conn;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment