Tom Lane wrote: > What would work better is to add some code that checks whether > pg_control_version looks like the byte-swap of a small number, > and prints a suitably modified error message if so.
Here is a possible patch. Example output: $ pg-install/bin/postgres -D pg-install/var/data FATAL: database files are incompatible with server DETAIL: The database cluster was initialized with PG_CONTROL_VERSION 1090715648 (0x41030000), but the server was compiled with PG_CONTROL_VERSION 833 (0x00000341). HINT: This could be a mismatched byte order. It looks like you need to initdb. I didn't follow how the user got into this mess, so I don't know whether the suggestion "you need to initdb" is appropriate. -- Peter Eisentraut http://developer.postgresql.org/~petere/
diff -ur ../cvs-pgsql/src/backend/access/transam/xlog.c ./src/backend/access/transam/xlog.c --- ../cvs-pgsql/src/backend/access/transam/xlog.c 2008-01-05 11:58:44.000000000 +0100 +++ ./src/backend/access/transam/xlog.c 2008-01-18 20:04:59.000000000 +0100 @@ -3888,6 +3888,16 @@ * 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 mismatched byte order. 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 @@ " 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, diff -ur ../cvs-pgsql/src/bin/pg_controldata/pg_controldata.c ./src/bin/pg_controldata/pg_controldata.c --- ../cvs-pgsql/src/bin/pg_controldata/pg_controldata.c 2007-04-03 22:26:13.000000000 +0200 +++ ./src/bin/pg_controldata/pg_controldata.c 2008-01-18 19:55:16.000000000 +0100 @@ -151,6 +151,11 @@ 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: possibly byte order mismatch\n" + "The byte order used to store the pg_control file might not match the one used\n" + "by this program. In that case the results below would be incorrect, and the\n" + "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"),
---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly