@@ -20,6 +20,7 @@ static void check_for_prepared_transactions(ClusterInfo *cluster);
20
20
static void check_for_isn_and_int8_passing_mismatch (ClusterInfo * cluster );
21
21
static void check_for_reg_data_type_usage (ClusterInfo * cluster );
22
22
static void check_for_support_lib (ClusterInfo * cluster );
23
+ static void get_bin_version (ClusterInfo * cluster );
23
24
24
25
25
26
void
@@ -217,6 +218,8 @@ output_completion_banner(char *deletion_script_file_name)
217
218
void
218
219
check_cluster_versions (void )
219
220
{
221
+ prep_status ("Checking cluster versions" );
222
+
220
223
/* get old and new cluster versions */
221
224
old_cluster .major_version = get_major_server_version (& old_cluster );
222
225
new_cluster .major_version = get_major_server_version (& new_cluster );
@@ -236,10 +239,26 @@ check_cluster_versions(void)
236
239
237
240
/*
238
241
* We can't allow downgrading because we use the target pg_dumpall, and
239
- * pg_dumpall cannot operate on newdatbase versions, only older versions.
242
+ * pg_dumpall cannot operate on newdatabase versions, only older versions.
240
243
*/
241
244
if (old_cluster .major_version > new_cluster .major_version )
242
245
pg_log (PG_FATAL ,"This utility cannot be used to downgrade to older major PostgreSQL versions.\n" );
246
+
247
+ /* get old and new binary versions */
248
+ get_bin_version (& old_cluster );
249
+ get_bin_version (& new_cluster );
250
+
251
+ /* Ensure binaries match the designated data directories */
252
+ if (GET_MAJOR_VERSION (old_cluster .major_version )!=
253
+ GET_MAJOR_VERSION (old_cluster .bin_version ))
254
+ pg_log (PG_FATAL ,
255
+ "Old cluster data and binary directories are from different major versions.\n" );
256
+ if (GET_MAJOR_VERSION (new_cluster .major_version )!=
257
+ GET_MAJOR_VERSION (new_cluster .bin_version ))
258
+ pg_log (PG_FATAL ,
259
+ "New cluster data and binary directories are from different major versions.\n" );
260
+
261
+ check_ok ();
243
262
}
244
263
245
264
@@ -756,3 +775,32 @@ check_for_support_lib(ClusterInfo *cluster)
756
775
757
776
fclose (lib_test );
758
777
}
778
+
779
+
780
+ static void
781
+ get_bin_version (ClusterInfo * cluster )
782
+ {
783
+ char cmd [MAXPGPATH ],cmd_output [MAX_STRING ];
784
+ FILE * output ;
785
+ int pre_dot ,post_dot ;
786
+
787
+ snprintf (cmd ,sizeof (cmd ),"\"%s/pg_ctl\" --version" ,cluster -> bindir );
788
+
789
+ if ((output = popen (cmd ,"r" ))== NULL )
790
+ pg_log (PG_FATAL ,"Could not get pg_ctl version data: %s\n" ,
791
+ getErrorText (errno ));
792
+
793
+ fgets (cmd_output ,sizeof (cmd_output ),output );
794
+
795
+ pclose (output );
796
+
797
+ /* Remove trailing newline */
798
+ if (strchr (cmd_output ,'\n' )!= NULL )
799
+ * strchr (cmd_output ,'\n' )= '\0' ;
800
+
801
+ if (sscanf (cmd_output ,"%*s %*s %d.%d" ,& pre_dot ,& post_dot )!= 2 )
802
+ pg_log (PG_FATAL ,"could not get version from %s\n" ,cmd );
803
+
804
+ cluster -> bin_version = (pre_dot * 100 + post_dot )* 100 ;
805
+ }
806
+