mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +03:00
Add a check to pg_dump to see whether backend is same version as pg_dump.
If not, abort by default. Abort can be prevented by using -i or --ignore-version switch.
This commit is contained in:
@ -22,7 +22,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.144 2000/02/07 16:30:58 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.145 2000/04/04 05:22:46 tgl Exp $
|
||||
*
|
||||
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
|
||||
*
|
||||
@ -139,6 +139,7 @@ help(const char *progname)
|
||||
" -d, --inserts dump data as INSERT, rather than COPY, commands\n"
|
||||
" -D, --attribute-inserts dump data as INSERT commands with attribute names\n"
|
||||
" -h, --host <hostname> server host name\n"
|
||||
" -i, --ignore-version proceed when database version != pg_dump version\n"
|
||||
" -n, --no-quotes suppress most quotes around identifiers\n"
|
||||
" -N, --quotes enable most quotes around identifiers\n"
|
||||
" -o, --oids dump object ids (oids)\n"
|
||||
@ -156,6 +157,7 @@ help(const char *progname)
|
||||
" -d dump data as INSERT, rather than COPY, commands\n"
|
||||
" -D dump data as INSERT commands with attribute names\n"
|
||||
" -h <hostname> server host name\n"
|
||||
" -i proceed when database version != pg_dump version\n"
|
||||
" -n suppress most quotes around identifiers\n"
|
||||
" -N enable most quotes around identifiers\n"
|
||||
" -o dump object ids (oids)\n"
|
||||
@ -533,6 +535,42 @@ prompt_for_password(char *username, char *password)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
check_database_version (bool ignoreVersion)
|
||||
{
|
||||
PGresult *res;
|
||||
const char *dbversion;
|
||||
const char *myversion = "PostgreSQL " PG_RELEASE "." PG_VERSION;
|
||||
int myversionlen = strlen(myversion);
|
||||
|
||||
res = PQexec(g_conn, "SELECT version()");
|
||||
if (!res ||
|
||||
PQresultStatus(res) != PGRES_TUPLES_OK ||
|
||||
PQntuples(res) != 1)
|
||||
{
|
||||
fprintf(stderr, "check_database_version(): command failed. Explanation from backend: '%s'.\n", PQerrorMessage(g_conn));
|
||||
exit_nicely(g_conn);
|
||||
}
|
||||
dbversion = PQgetvalue(res, 0, 0);
|
||||
if (strncmp(dbversion, myversion, myversionlen) != 0)
|
||||
{
|
||||
fprintf(stderr, "Database version: %s\npg_dump version: %s\n",
|
||||
dbversion, PG_RELEASE "." PG_VERSION);
|
||||
if (ignoreVersion)
|
||||
{
|
||||
fprintf(stderr, "Proceeding despite version mismatch.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Aborting because of version mismatch.\n"
|
||||
"Use --ignore-version if you think it's safe to proceed anyway.\n");
|
||||
exit_nicely(g_conn);
|
||||
}
|
||||
}
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -551,6 +589,7 @@ main(int argc, char **argv)
|
||||
char username[100];
|
||||
char password[100];
|
||||
bool use_password = false;
|
||||
bool ignore_version = false;
|
||||
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
static struct option long_options[] = {
|
||||
@ -559,6 +598,7 @@ main(int argc, char **argv)
|
||||
{"inserts",no_argument, NULL, 'd'},
|
||||
{"attribute-inserts", no_argument, NULL, 'D'},
|
||||
{"host", required_argument, NULL, 'h'},
|
||||
{"ignore-version", no_argument, NULL, 'i'},
|
||||
{"no-quotes", no_argument, NULL, 'n'},
|
||||
{"quotes", no_argument, NULL, 'N'},
|
||||
{"oids", no_argument, NULL, 'o'},
|
||||
@ -591,9 +631,9 @@ main(int argc, char **argv)
|
||||
|
||||
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
while ((c = getopt_long(argc, argv, "acdDf:h:nNop:st:uvxzV?", long_options, &optindex)) != -1)
|
||||
while ((c = getopt_long(argc, argv, "acdDf:h:inNop:st:uvxzV?", long_options, &optindex)) != -1)
|
||||
#else
|
||||
while ((c = getopt(argc, argv, "acdDf:h:nNop:st:uvxzV?-")) != -1)
|
||||
while ((c = getopt(argc, argv, "acdDf:h:inNop:st:uvxzV?-")) != -1)
|
||||
#endif
|
||||
{
|
||||
switch (c)
|
||||
@ -614,11 +654,14 @@ main(int argc, char **argv)
|
||||
attrNames = true;
|
||||
break;
|
||||
case 'f':
|
||||
filename = optarg;
|
||||
break;
|
||||
filename = optarg;
|
||||
break;
|
||||
case 'h': /* server host */
|
||||
pghost = optarg;
|
||||
break;
|
||||
case 'i': /* ignore database version mismatch */
|
||||
ignore_version = true;
|
||||
break;
|
||||
case 'n': /* Do not force double-quotes on
|
||||
* identifiers */
|
||||
force_quotes = false;
|
||||
@ -773,6 +816,9 @@ main(int argc, char **argv)
|
||||
exit_nicely(g_conn);
|
||||
}
|
||||
|
||||
/* check for version mismatch */
|
||||
check_database_version(ignore_version);
|
||||
|
||||
/*
|
||||
* Start serializable transaction to dump consistent data
|
||||
*/
|
||||
|
Reference in New Issue
Block a user