Turn the -i/--ignore-version options of pg_dump and pg_dumpall into no-ops:

the server version check is now always enforced.  Relax the version check to
allow a server that is of pg_dump's own major version but a later minor
version; this is the only case that -i was at all safe to use in.

pg_restore already enforced only a very weak version check, so this is
really just a documentation change for it.

Per discussion.
This commit is contained in:
Tom Lane 2008-04-13 03:49:22 +00:00
parent ba1c463096
commit c22ed3d523
9 changed files with 46 additions and 82 deletions

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.101 2008/03/26 16:34:47 tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.102 2008/04/13 03:49:21 tgl Exp $
PostgreSQL documentation
-->
@ -296,20 +296,7 @@ PostgreSQL documentation
<term><option>--ignore-version</></term>
<listitem>
<para>
Ignore version mismatch between
<application>pg_dump</application> and the database server.
</para>
<para>
By default, <application>pg_dump</> will refuse to attempt
to dump from a server that is of a newer <productname>PostgreSQL</>
version than <application>pg_dump</application> is. It will also
refuse to attempt to dump from a server that is older than the oldest
supported version (currently, 7.0). The <option>-i</> option
overrides this check and forces a dump to be attempted anyway.
This option is <emphasis>deprecated</> because the dump is very
likely to fail &mdash; or worse, seem to succeed but be wrong or
incomplete.
A deprecated option that is now ignored.
</para>
</listitem>
</varlistentry>

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.71 2008/03/26 16:34:47 tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.72 2008/04/13 03:49:21 tgl Exp $
PostgreSQL documentation
-->
@ -156,20 +156,7 @@ PostgreSQL documentation
<term><option>--ignore-version</></term>
<listitem>
<para>
Ignore version mismatch between
<application>pg_dumpall</application> and the database server.
</para>
<para>
By default, <application>pg_dumpall</> will refuse to attempt
to dump from a server that is of a newer <productname>PostgreSQL</>
version than <application>pg_dumpall</application> is. It will also
refuse to attempt to dump from a server that is older than the oldest
supported version (currently, 7.0). The <option>-i</> option
overrides this check and forces a dump to be attempted anyway.
This option is <emphasis>deprecated</> because the dump is very
likely to fail &mdash; or worse, seem to succeed but be wrong or
incomplete.
A deprecated option that is now ignored.
</para>
</listitem>
</varlistentry>

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.74 2008/03/26 16:34:47 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.75 2008/04/13 03:49:21 tgl Exp $ -->
<refentry id="APP-PGRESTORE">
<refmeta>
@ -200,8 +200,7 @@
<term><option>--ignore-version</option></term>
<listitem>
<para>
Ignore version mismatch between
<application>pg_restore</application> and the database server.
A deprecated option that is now ignored.
</para>
</listitem>
</varlistentry>

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.46 2008/03/20 17:36:57 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.47 2008/04/13 03:49:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -116,7 +116,6 @@ typedef struct _restoreOptions
char *pgport;
char *pghost;
char *username;
int ignoreVersion;
int noDataForFailedTables;
int requirePassword;
int exit_on_error;
@ -144,9 +143,7 @@ PGconn *ConnectDatabase(Archive *AH,
const char *pghost,
const char *pgport,
const char *username,
const int reqPwd,
const int ignoreVersion);
int reqPwd);
/* Called to add a TOC entry */
extern void ArchiveEntry(Archive *AHX,

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.153 2008/03/20 17:36:57 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.154 2008/04/13 03:49:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -162,7 +162,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
ConnectDatabase(AHX, ropt->dbname,
ropt->pghost, ropt->pgport, ropt->username,
ropt->requirePassword, ropt->ignoreVersion);
ropt->requirePassword);
/*
* If we're talking to the DB directly, don't send comments since they

View File

@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.78 2008/03/26 14:32:22 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.79 2008/04/13 03:49:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -24,7 +24,7 @@
static const char *modulename = gettext_noop("archiver (db)");
static void _check_database_version(ArchiveHandle *AH, bool ignoreVersion);
static void _check_database_version(ArchiveHandle *AH);
static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser);
static void notice_processor(void *arg, const char *message);
static char *_sendSQLLine(ArchiveHandle *AH, char *qry, char *eos);
@ -48,7 +48,7 @@ _parse_version(ArchiveHandle *AH, const char *versionString)
}
static void
_check_database_version(ArchiveHandle *AH, bool ignoreVersion)
_check_database_version(ArchiveHandle *AH)
{
int myversion;
const char *remoteversion_str;
@ -71,11 +71,7 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
{
write_msg(NULL, "server version: %s; %s version: %s\n",
remoteversion_str, progname, PG_VERSION);
if (ignoreVersion)
write_msg(NULL, "ignoring server version mismatch\n");
else
die_horribly(AH, NULL, "aborting because of server version mismatch\n"
"Use the -i option to bypass server version check, but be prepared for failure.\n");
die_horribly(AH, NULL, "aborting because of server version mismatch\n");
}
}
@ -182,7 +178,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
free(password);
/* check for version mismatch */
_check_database_version(AH, true);
_check_database_version(AH);
PQsetNoticeProcessor(newConn, notice_processor, NULL);
@ -201,8 +197,7 @@ ConnectDatabase(Archive *AHX,
const char *pghost,
const char *pgport,
const char *username,
const int reqPwd,
const int ignoreVersion)
int reqPwd)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
char *password = NULL;
@ -254,7 +249,7 @@ ConnectDatabase(Archive *AHX,
PQdb(AH->connection), PQerrorMessage(AH->connection));
/* check for version mismatch */
_check_database_version(AH, ignoreVersion);
_check_database_version(AH);
PQsetNoticeProcessor(AH->connection, notice_processor, NULL);

View File

@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.486 2008/03/28 00:21:56 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.487 2008/04/13 03:49:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -211,19 +211,20 @@ main(int argc, char **argv)
int i;
bool force_password = false;
int compressLevel = -1;
bool ignore_version = false;
int plainText = 0;
int outputClean = 0;
int outputCreate = 0;
bool outputBlobs = false;
int outputNoOwner = 0;
char *outputSuperuser = NULL;
int my_version;
int optindex;
RestoreOptions *ropt;
static int disable_triggers = 0;
static int outputNoTablespaces = 0;
static int use_setsessauth = 0;
RestoreOptions *ropt;
static struct option long_options[] = {
{"data-only", no_argument, NULL, 'a'},
{"blobs", no_argument, NULL, 'b'},
@ -266,7 +267,6 @@ main(int argc, char **argv)
{NULL, 0, NULL, 0}
};
int optindex;
set_pglocale_pgservice(argv[0], "pg_dump");
@ -345,8 +345,8 @@ main(int argc, char **argv)
pghost = optarg;
break;
case 'i': /* ignore database version mismatch */
ignore_version = true;
case 'i':
/* ignored, deprecated option */
break;
case 'n': /* include schema(s) */
@ -512,20 +512,26 @@ 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)
my_version = parse_version(PG_VERSION);
if (my_version < 0)
{
write_msg(NULL, "could not parse version string \"%s\"\n", PG_VERSION);
exit(1);
}
/*
* We allow the server to be back to 7.0, and up to any minor release
* of our own major version. (See also version check in pg_dumpall.c.)
*/
g_fout->minRemoteVersion = 70000;
g_fout->maxRemoteVersion = (my_version / 100) * 100 + 99;
/*
* Open the database using the Archiver, so it knows about it. Errors mean
* death.
*/
g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport,
username, force_password, ignore_version);
username, force_password);
/* Set the client encoding if requested */
if (dumpencoding)
@ -739,7 +745,6 @@ help(const char *progname)
printf(_("\nGeneral options:\n"));
printf(_(" -f, --file=FILENAME output file name\n"));
printf(_(" -F, --format=c|t|p output file format (custom, tar, plain text)\n"));
printf(_(" -i, --ignore-version ignore server version mismatch\n"));
printf(_(" -v, --verbose verbose mode\n"));
printf(_(" -Z, --compress=0-9 compression level for compressed formats\n"));
printf(_(" --help show this help, then exit\n"));

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.103 2008/03/26 14:32:22 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.104 2008/04/13 03:49:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -60,7 +60,6 @@ static PQExpBuffer pgdumpopts;
static bool output_clean = false;
static bool skip_acls = false;
static bool verbose = false;
static bool ignoreVersion = false;
static int disable_dollar_quoting = 0;
static int disable_triggers = 0;
@ -214,8 +213,7 @@ main(int argc, char *argv[])
break;
case 'i':
ignoreVersion = true;
appendPQExpBuffer(pgdumpopts, " -i");
/* ignored, deprecated option */
break;
case 'l':
@ -488,7 +486,6 @@ help(void)
printf(_("\nGeneral options:\n"));
printf(_(" -f, --file=FILENAME output file name\n"));
printf(_(" -i, --ignore-version ignore server version mismatch\n"));
printf(_(" --help show this help, then exit\n"));
printf(_(" --version output version information, then exit\n"));
printf(_("\nOptions controlling the output content:\n"));
@ -1391,20 +1388,18 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
exit(1);
}
/*
* We allow the server to be back to 7.0, and up to any minor release
* of our own major version. (See also version check in pg_dump.c.)
*/
if (my_version != server_version
&& (server_version < 70000 /* we can handle back to 7.0 */
|| server_version > my_version))
&& (server_version < 70000 ||
(server_version / 100) > (my_version / 100)))
{
fprintf(stderr, _("server version: %s; %s version: %s\n"),
remoteversion_str, progname, PG_VERSION);
if (ignoreVersion)
fprintf(stderr, _("ignoring server version mismatch\n"));
else
{
fprintf(stderr, _("aborting because of server version mismatch\n"
"Use the -i option to bypass server version check, but be prepared for failure.\n"));
exit(1);
}
fprintf(stderr, _("aborting because of server version mismatch\n"));
exit(1);
}
/*

View File

@ -34,7 +34,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.87 2008/03/26 14:32:22 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.88 2008/04/13 03:49:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -171,7 +171,7 @@ main(int argc, char **argv)
opts->pghost = strdup(optarg);
break;
case 'i':
opts->ignoreVersion = 1;
/* ignored, deprecated option */
break;
case 'l': /* Dump the TOC summary */
@ -378,7 +378,6 @@ usage(const char *progname)
printf(_(" -d, --dbname=NAME connect to database name\n"));
printf(_(" -f, --file=FILENAME output file name\n"));
printf(_(" -F, --format=c|t specify backup file format\n"));
printf(_(" -i, --ignore-version ignore server version mismatch\n"));
printf(_(" -l, --list print summarized TOC of the archive\n"));
printf(_(" -v, --verbose verbose mode\n"));
printf(_(" --help show this help, then exit\n"));