Commit fa339565 authored by Michael Paquier's avatar Michael Paquier

Error out in pg_checksums on incompatible block size

pg_checksums is compiled with a given block size and has a hard
dependency to it per the way checksums are calculated via
checksum_impl.h, and trying to use the tool on a data folder which has
not the same block size would result in incorrect checksum calculations
and/or block read errors, meaning that the data folder is corrupted.
This is harmless as checksums are only checked now, but very confusing
for the user so issue an error properly if the block size used at
compilation and the block size used in the data folder do not match.

Reported-by: Sergei Kornilov
Author: Michael Banck, Michael Paquier
Reviewed-by: Fabien Coelho, Magnus Hagander
Discussion: https://postgr.es/m/20190317054657.GA3357@paquier.xyz
ackpatch-through: 11
parent 4178d8b9
...@@ -327,6 +327,15 @@ main(int argc, char *argv[]) ...@@ -327,6 +327,15 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
if (ControlFile->blcksz != BLCKSZ)
{
fprintf(stderr, _("%s: database cluster is not compatible.\n"),
progname);
fprintf(stderr, _("The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.\n"),
ControlFile->blcksz, BLCKSZ);
exit(1);
}
if (ControlFile->state != DB_SHUTDOWNED && if (ControlFile->state != DB_SHUTDOWNED &&
ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY) ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment