src/backend/utils/init/miscinit.c
/*
 * Determine whether the PG_VERSION file in directory `path' indicates
 * a data version compatible with the version of this program.
 *
 * If compatible, return. Otherwise, ereport(FATAL).
 */
Determine whether the PG_VERSION file in directory `path' indicates
a data version compatible with the version of this program.

If compatible, return.
Determine whether the PG_VERSION file in directory ` path ' indicates a data version compatible with the version of this program . If compatible return .
void
ValidatePgVersion(const char *path)
{
	char		full_path[MAXPGPATH];
	FILE	   *file;
	int			ret;
	long		file_major,
				file_minor;
	long		my_major = 0,
				my_minor = 0;
	char	   *endptr;
	const char *version_string = PG_VERSION;
	my_major = strtol(version_string, &endptr, 10);
	if (*endptr == '.')
		my_minor = strtol(endptr + 1, NULL, 10);
	snprintf(full_path, sizeof(full_path), "%s/PG_VERSION", path);
	file = AllocateFile(full_path, "r");
	if (!file)
	{
		if (errno == ENOENT)
			ereport(FATAL,
					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
					 errmsg("\"%s\" is not a valid data directory",
							path),
					 errdetail("File \"%s\" is missing.", full_path)));
		else
			ereport(FATAL,
					(errcode_for_file_access(),
					 errmsg("could not open file \"%s\": %m", full_path)));
	}
	ret = fscanf(file, "%ld.%ld", &file_major, &file_minor);
	if (ret != 2)
		ereport(FATAL,
				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
				 errmsg("\"%s\" is not a valid data directory",
						path),
				 errdetail("File \"%s\" does not contain valid data.",
						   full_path),
				 errhint("You might need to run gprecoversegment.sh")));
	FreeFile(file);
	if (my_major != file_major || my_minor != file_minor)
		ereport(FATAL,
				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
				 errmsg("database files are incompatible with server"),
				 errdetail("The data directory was initialized by PostgreSQL version %ld.%ld, "
						   "which is not compatible with this version %s.",
						   file_major, file_minor, version_string)));
}
void ValidatePgVersion ( const char * path ) { char full_path [ MAXPGPATH ] ; FILE * file ; int ret ; long file_major , file_minor ; long my_major = 0 , my_minor = 0 ; char * endptr ; const char * version_string = PG_VERSION ; my_major = strtol ( version_string , & endptr , 10 ) ; if ( * endptr == ' ' ) my_minor = strtol ( endptr + 1 , NULL , 10 ) ; snprintf ( full_path , sizeof ( full_path ) , " " , path ) ; file = AllocateFile ( full_path , " " ) ; if ( ! file ) { if ( errno == ENOENT ) ereport ( FATAL , ( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) , errmsg ( " \" \" " , path ) , errdetail ( " \" \" " , full_path ) ) ) ; else ereport ( FATAL , ( errcode_for_file_access ( ) , errmsg ( " \" \" " , full_path ) ) ) ; } ret = fscanf ( file , " " , & file_major , & file_minor ) ; if ( ret != 2 ) ereport ( FATAL , ( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) , errmsg ( " \" \" " , path ) , errdetail ( " \" \" " , full_path ) , errhint ( " " ) ) ) ; FreeFile ( file ) ; if ( my_major != file_major || my_minor != file_minor ) ereport ( FATAL , ( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) , errmsg ( " " ) , errdetail ( " " " " , file_major , file_minor , version_string ) ) ) ; }
Determine whether the PG_VERSION file in directory `path' indicates
 a data version compatible with the version of this program.
Determine whether the PG_VERSION file in directory ` path ' indicates a data version compatible with the version of this program .