22
22
*
23
23
*
24
24
* 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 $
26
26
*
27
27
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
28
28
*
@@ -139,6 +139,7 @@ help(const char *progname)
139
139
" -d, --inserts dump data as INSERT, rather than COPY, commands\n"
140
140
" -D, --attribute-inserts dump data as INSERT commands with attribute names\n"
141
141
" -h, --host <hostname> server host name\n"
142
+ " -i, --ignore-version proceed when database version != pg_dump version\n"
142
143
" -n, --no-quotes suppress most quotes around identifiers\n"
143
144
" -N, --quotes enable most quotes around identifiers\n"
144
145
" -o, --oids dump object ids (oids)\n"
@@ -156,6 +157,7 @@ help(const char *progname)
156
157
" -d dump data as INSERT, rather than COPY, commands\n"
157
158
" -D dump data as INSERT commands with attribute names\n"
158
159
" -h <hostname> server host name\n"
160
+ " -i proceed when database version != pg_dump version\n"
159
161
" -n suppress most quotes around identifiers\n"
160
162
" -N enable most quotes around identifiers\n"
161
163
" -o dump object ids (oids)\n"
@@ -533,6 +535,42 @@ prompt_for_password(char *username, char *password)
533
535
}
534
536
535
537
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
+
536
574
int
537
575
main (int argc , char * * argv )
538
576
{
@@ -551,6 +589,7 @@ main(int argc, char **argv)
551
589
char username [100 ];
552
590
char password [100 ];
553
591
bool use_password = false;
592
+ bool ignore_version = false;
554
593
555
594
#ifdef HAVE_GETOPT_LONG
556
595
static struct option long_options [] = {
@@ -559,6 +598,7 @@ main(int argc, char **argv)
559
598
{"inserts" ,no_argument , NULL , 'd' },
560
599
{"attribute-inserts" , no_argument , NULL , 'D' },
561
600
{"host" , required_argument , NULL , 'h' },
601
+ {"ignore-version" , no_argument , NULL , 'i' },
562
602
{"no-quotes" , no_argument , NULL , 'n' },
563
603
{"quotes" , no_argument , NULL , 'N' },
564
604
{"oids" , no_argument , NULL , 'o' },
@@ -591,9 +631,9 @@ main(int argc, char **argv)
591
631
592
632
593
633
#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 )
595
635
#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 )
597
637
#endif
598
638
{
599
639
switch (c )
@@ -614,11 +654,14 @@ main(int argc, char **argv)
614
654
attrNames = true;
615
655
break ;
616
656
case 'f' :
617
- filename = optarg ;
618
- break ;
657
+ filename = optarg ;
658
+ break ;
619
659
case 'h' : /* server host */
620
660
pghost = optarg ;
621
661
break ;
662
+ case 'i' : /* ignore database version mismatch */
663
+ ignore_version = true;
664
+ break ;
622
665
case 'n' : /* Do not force double-quotes on
623
666
* identifiers */
624
667
force_quotes = false;
@@ -773,6 +816,9 @@ main(int argc, char **argv)
773
816
exit_nicely (g_conn );
774
817
}
775
818
819
+ /* check for version mismatch */
820
+ check_database_version (ignore_version );
821
+
776
822
/*
777
823
* Start serializable transaction to dump consistent data
778
824
*/
0 commit comments