2222 *
2323 *
2424 * IDENTIFICATION
25- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.144 2000/02/07 16:30:58 wieck Exp $
25+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.145 2000/04/04 05:22:46 tgl Exp $
2626 *
2727 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828 *
@@ -139,6 +139,7 @@ help(const char *progname)
139139" -d, --inserts dump data as INSERT, rather than COPY, commands\n"
140140" -D, --attribute-inserts dump data as INSERT commands with attribute names\n"
141141" -h, --host <hostname> server host name\n"
142+ " -i, --ignore-version proceed when database version != pg_dump version\n"
142143" -n, --no-quotes suppress most quotes around identifiers\n"
143144" -N, --quotes enable most quotes around identifiers\n"
144145" -o, --oids dump object ids (oids)\n"
@@ -156,6 +157,7 @@ help(const char *progname)
156157" -d dump data as INSERT, rather than COPY, commands\n"
157158" -D dump data as INSERT commands with attribute names\n"
158159" -h <hostname> server host name\n"
160+ " -i proceed when database version != pg_dump version\n"
159161" -n suppress most quotes around identifiers\n"
160162" -N enable most quotes around identifiers\n"
161163" -o dump object ids (oids)\n"
@@ -533,6 +535,42 @@ prompt_for_password(char *username, char *password)
533535}
534536
535537
538+ static void
539+ check_database_version (bool ignoreVersion )
540+ {
541+ PGresult * res ;
542+ const char * dbversion ;
543+ const char * myversion = "PostgreSQL " PG_RELEASE "." PG_VERSION ;
544+ int myversionlen = strlen (myversion );
545+
546+ res = PQexec (g_conn ,"SELECT version()" );
547+ if (!res ||
548+ PQresultStatus (res )!= PGRES_TUPLES_OK ||
549+ PQntuples (res )!= 1 )
550+ {
551+ fprintf (stderr ,"check_database_version(): command failed. Explanation from backend: '%s'.\n" ,PQerrorMessage (g_conn ));
552+ exit_nicely (g_conn );
553+ }
554+ dbversion = PQgetvalue (res ,0 ,0 );
555+ if (strncmp (dbversion ,myversion ,myversionlen )!= 0 )
556+ {
557+ fprintf (stderr ,"Database version: %s\npg_dump version: %s\n" ,
558+ dbversion ,PG_RELEASE "." PG_VERSION );
559+ if (ignoreVersion )
560+ {
561+ fprintf (stderr ,"Proceeding despite version mismatch.\n" );
562+ }
563+ else
564+ {
565+ fprintf (stderr ,"Aborting because of version mismatch.\n"
566+ "Use --ignore-version if you think it's safe to proceed anyway.\n" );
567+ exit_nicely (g_conn );
568+ }
569+ }
570+ PQclear (res );
571+ }
572+
573+
536574int
537575main (int argc ,char * * argv )
538576{
@@ -551,6 +589,7 @@ main(int argc, char **argv)
551589char username [100 ];
552590char password [100 ];
553591bool use_password = false;
592+ bool ignore_version = false;
554593
555594#ifdef HAVE_GETOPT_LONG
556595static struct option long_options []= {
@@ -559,6 +598,7 @@ main(int argc, char **argv)
559598{"inserts" ,no_argument ,NULL ,'d' },
560599{"attribute-inserts" ,no_argument ,NULL ,'D' },
561600{"host" ,required_argument ,NULL ,'h' },
601+ {"ignore-version" ,no_argument ,NULL ,'i' },
562602{"no-quotes" ,no_argument ,NULL ,'n' },
563603{"quotes" ,no_argument ,NULL ,'N' },
564604{"oids" ,no_argument ,NULL ,'o' },
@@ -591,9 +631,9 @@ main(int argc, char **argv)
591631
592632
593633#ifdef HAVE_GETOPT_LONG
594- while ((c = getopt_long (argc ,argv ,"acdDf:h:nNop :st:uvxzV?" ,long_options ,& optindex ))!= -1 )
634+ while ((c = getopt_long (argc ,argv ,"acdDf:h:inNop :st:uvxzV?" ,long_options ,& optindex ))!= -1 )
595635#else
596- while ((c = getopt (argc ,argv ,"acdDf:h:nNop :st:uvxzV?-" ))!= -1 )
636+ while ((c = getopt (argc ,argv ,"acdDf:h:inNop :st:uvxzV?-" ))!= -1 )
597637#endif
598638{
599639switch (c )
@@ -614,11 +654,14 @@ main(int argc, char **argv)
614654attrNames = true;
615655break ;
616656case 'f' :
617- filename = optarg ;
618- break ;
657+ filename = optarg ;
658+ break ;
619659case 'h' :/* server host */
620660pghost = optarg ;
621661break ;
662+ case 'i' :/* ignore database version mismatch */
663+ ignore_version = true;
664+ break ;
622665case 'n' :/* Do not force double-quotes on
623666 * identifiers */
624667force_quotes = false;
@@ -773,6 +816,9 @@ main(int argc, char **argv)
773816exit_nicely (g_conn );
774817}
775818
819+ /* check for version mismatch */
820+ check_database_version (ignore_version );
821+
776822/*
777823 * Start serializable transaction to dump consistent data
778824 */