<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.15 2000/03/27 17:14:43 thomas Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.16 2000/04/04 05:22:45 tgl Exp $
Postgres documentation
-->
pg_dump [ <replaceable class="parameter">dbname</replaceable> ]
pg_dump [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ]
[ -t <replaceable class="parameter">table</replaceable> ]
- [ -a ] [ -c ] [ -d ] [ -D ] [ -n ] [ -N ]
+ [ -a ] [ -c ] [ -d ] [ -D ] [ -i ] [ -n ] [ -N ]
[ -o ] [ -s ] [ -u ] [ -v ] [ -x ]
[ <replaceable class="parameter">dbname</replaceable> ]
</synopsis>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>-i</term>
+ <listitem>
+ <para>
+ Ignore version mismatch between <application>pg_dump</application>
+ and the database server. Since <application>pg_dump</application>
+ knows a great deal about system catalogs, any given version of
+ <application>pg_dump</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
+ <application>pg_dump</application> then fails, don't
+ say you weren't warned).
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term>-n</term>
<listitem>
*
*
* 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
*
" -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"
" -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"
}
+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)
{
char username[100];
char password[100];
bool use_password = false;
+ bool ignore_version = false;
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] = {
{"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'},
#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)
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;
exit_nicely(g_conn);
}
+ /* check for version mismatch */
+ check_database_version(ignore_version);
+
/*
* Start serializable transaction to dump consistent data
*/