@@ -38,7 +38,8 @@ usage(const char *progname)
38
38
printf (_ (" %s [OPTION] [DATADIR]\n" ),progname );
39
39
printf (_ ("\nOptions:\n" ));
40
40
printf (_ (" [-D] DATADIR data directory\n" ));
41
- printf (_ (" [-c] update catversion in pg_control to the verision of the current binary\n" ));
41
+ printf (_ (" [-c] update catversion in pg_control to the verision of the current binary\n" ));
42
+ printf (_ (" [-m] check if catversion in pg_control matches catverision of the current binary. Return 0 on match, 1 otherwise.\n" ));
42
43
printf (_ (" -V, --version output version information, then exit\n" ));
43
44
printf (_ (" -?, --help show this help, then exit\n" ));
44
45
printf (_ ("\nIf no data directory (DATADIR) is specified, "
@@ -101,6 +102,7 @@ main(int argc, char *argv[])
101
102
char xlogfilename [MAXFNAMELEN ];
102
103
int c ;
103
104
bool reset_catversion = false;
105
+ bool check_catversion_match = false;
104
106
105
107
set_pglocale_pgservice (argv [0 ],PG_TEXTDOMAIN ("pg_controldata" ));
106
108
@@ -120,7 +122,7 @@ main(int argc, char *argv[])
120
122
}
121
123
}
122
124
123
- while ((c = getopt (argc ,argv ,"D:c" ))!= -1 )
125
+ while ((c = getopt (argc ,argv ,"D:c:m " ))!= -1 )
124
126
{
125
127
switch (c )
126
128
{
@@ -130,7 +132,9 @@ main(int argc, char *argv[])
130
132
case 'c' :
131
133
reset_catversion = true;
132
134
break ;
133
-
135
+ case 'm' :
136
+ check_catversion_match = true;
137
+ break ;
134
138
default :
135
139
fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),progname );
136
140
exit (1 );
@@ -165,6 +169,14 @@ main(int argc, char *argv[])
165
169
/* get a copy of the control file */
166
170
ControlFile = get_controlfile (DataDir ,progname );
167
171
172
+ if (check_catversion_match )
173
+ {
174
+ if (ControlFile -> catalog_version_no == CATALOG_VERSION_NO )
175
+ return 0 ;
176
+ else
177
+ return 1 ;
178
+ }
179
+
168
180
if (reset_catversion )
169
181
{
170
182
ControlFile -> catalog_version_no = CATALOG_VERSION_NO ;