]> granicus.if.org Git - postgresql/commitdiff
Provide a clearer error message if the pg_control version number looks
authorPeter Eisentraut <peter_e@gmx.net>
Mon, 21 Jan 2008 11:17:46 +0000 (11:17 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 21 Jan 2008 11:17:46 +0000 (11:17 +0000)
wrong because of mismatched byte ordering.

src/backend/access/transam/xlog.c
src/bin/pg_controldata/pg_controldata.c

index 165ed51c2cafada7f84f11af81fad105c0269022..d2075018d96d0547dcb3bb547897aaec67c32d4c 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.291 2008/01/01 19:45:48 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.292 2008/01/21 11:17:46 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -3888,6 +3888,16 @@ ReadControlFile(void)
         * of bytes.  Complaining about wrong version will probably be more
         * enlightening than complaining about wrong CRC.
         */
+
+       if (ControlFile->pg_control_version != PG_CONTROL_VERSION && ControlFile->pg_control_version % 65536 == 0 && ControlFile->pg_control_version / 65536 != 0)
+               ereport(FATAL,
+                               (errmsg("database files are incompatible with server"),
+                                errdetail("The database cluster was initialized with PG_CONTROL_VERSION %d (0x%08x),"
+                                                  " but the server was compiled with PG_CONTROL_VERSION %d (0x%08x).",
+                                                  ControlFile->pg_control_version, ControlFile->pg_control_version,
+                                                  PG_CONTROL_VERSION, PG_CONTROL_VERSION),
+                                errhint("This could be a problem of mismatched byte ordering.  It looks like you need to initdb.")));
+
        if (ControlFile->pg_control_version != PG_CONTROL_VERSION)
                ereport(FATAL,
                                (errmsg("database files are incompatible with server"),
@@ -3895,6 +3905,7 @@ ReadControlFile(void)
                                  " but the server was compiled with PG_CONTROL_VERSION %d.",
                                                ControlFile->pg_control_version, PG_CONTROL_VERSION),
                                 errhint("It looks like you need to initdb.")));
+
        /* Now check the CRC. */
        INIT_CRC32(crc);
        COMP_CRC32(crc,
index 6538da6a56dea34a6f09ecd26f60fecb7dc72911..682a5cf380779646a197f9c6e3396e5624145630 100644 (file)
@@ -6,7 +6,7 @@
  * copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
  * licence: BSD
  *
- * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.35 2007/04/03 04:14:26 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.36 2008/01/21 11:17:46 petere Exp $
  */
 #include "postgres.h"
 
@@ -151,6 +151,11 @@ main(int argc, char *argv[])
 
        printf(_("pg_control version number:            %u\n"),
                   ControlFile.pg_control_version);
+       if (ControlFile.pg_control_version % 65536 == 0 && ControlFile.pg_control_version / 65536 != 0)
+               printf(_("WARNING: possible byte ordering mismatch\n"
+                                "The byte ordering used to store the pg_control file might not match the one\n"
+                                "used by this program.  In that case the results below would be incorrect, and\n"
+                                "the PostgreSQL installation would be incompatible with this data directory.\n"));
        printf(_("Catalog version number:               %u\n"),
                   ControlFile.catalog_version_no);
        printf(_("Database system identifier:           %s\n"),