This patches checks MAXIMUM_ALIGNOF and endian to make sure that the
database file used is compatible with the server version. We use
SHORT_ALIGNOF, INT_ALIGNOF, DOUBLE_ALIGNOF and MAXIMUM_ALIGNOF (which is
just the largest of these) to align columns within a row (see att_align())
or rows within a page. On all platforms we know, SHORT_ALIGNOF is 2, and
we only support platforms with INT_ALIGOF equals to 4. What it comes down
to is that MAXIMUM_ALIGNOF is sufficient to tell the difference between
the platforms we need to deal with. Also, check the endian to make sure
that the multibytes numbers storage is compatible.
Regards, Qingqing
---
Index: backend/access/transam/xlog.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.218
diff -c -r1.218 xlog.c
*** backend/access/transam/xlog.c 22 Aug 2005 23:59:04 - 1.218
--- backend/access/transam/xlog.c 2 Oct 2005 18:08:25 -
***
*** 3420,3425
--- 3420,3427
ControlFile-blcksz = BLCKSZ;
ControlFile-relseg_size = RELSEG_SIZE;
ControlFile-xlog_seg_size = XLOG_SEG_SIZE;
+ ControlFile-maximum_alignof = MAXIMUM_ALIGNOF;
+ ControlFile-endian = ENDIAN_CODE;
ControlFile-nameDataLen = NAMEDATALEN;
ControlFile-indexMaxKeys = INDEX_MAX_KEYS;
***
*** 3583,3588
--- 3585,3604
but the server was compiled with
XLOG_SEG_SIZE %d.,
ControlFile-xlog_seg_size,
XLOG_SEG_SIZE),
errhint(It looks like you need to recompile or
initdb.)));
+ if (ControlFile-maximum_alignof != MAXIMUM_ALIGNOF)
+ ereport(FATAL,
+ (errmsg(database files are incompatible with
server),
+errdetail(The database cluster was
initialized with MAXIMUM_ALIGNOF
+ %d,
+ but the server was compiled with
MAXIMUM_ALIGNOF %d.,
+ ControlFile-maximum_alignof,
MAXIMUM_ALIGNOF),
+errhint(It looks like you need to recompile or
initdb.)));
+ if (ControlFile-endian != ENDIAN_CODE)
+ ereport(FATAL,
+ (errmsg(database files are incompatible with
server),
+errdetail(The database cluster was
initialized with different
+ endian with the server),
+errhint(It looks like you need to recompile or
initdb.)));
if (ControlFile-nameDataLen != NAMEDATALEN)
ereport(FATAL,
(errmsg(database files are incompatible with
server),
Index: backend/storage/freespace/freespace.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/storage/freespace/freespace.c,v
retrieving revision 1.48
diff -c -r1.48 freespace.c
*** backend/storage/freespace/freespace.c 20 Aug 2005 23:26:20 -
1.48
--- backend/storage/freespace/freespace.c 2 Oct 2005 18:08:26 -
***
*** 116,122
*
* The file format is:
*label FSM\0
- *endian constant 0x01020304 for detecting
endianness problems
*version#
*numRels
*-- for each rel, in *reverse* usage order:
--- 116,121
***
*** 134,147
/* Fixed values in header */
#define FSM_CACHE_LABEL FSM
- #define FSM_CACHE_ENDIAN 0x01020304
#define FSM_CACHE_VERSION 20030305
/* File header layout */
typedef struct FsmCacheFileHeader
{
charlabel[4];
- uint32 endian;
uint32 version;
int32 numRels;
} FsmCacheFileHeader;
--- 133,144
***
*** 767,773
/* Write file header */
MemSet(header, 0, sizeof(header));
strcpy(header.label, FSM_CACHE_LABEL);
- header.endian = FSM_CACHE_ENDIAN;
header.version = FSM_CACHE_VERSION;
header.numRels = FreeSpaceMap-numRels;
if (fwrite(header, 1, sizeof(header), fp) != sizeof(header))
--- 764,769
***
*** 868,874
/* Read and verify file header */
if (fread(header, 1, sizeof(header), fp) != sizeof(header) ||
strcmp(header.label, FSM_CACHE_LABEL) != 0 ||
- header.endian != FSM_CACHE_ENDIAN ||
header.version != FSM_CACHE_VERSION ||
header.numRels 0)
{
--- 864,869
Index: bin/pg_controldata/pg_controldata.c
===
RCS file: /projects/cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v
retrieving revision 1.25
diff -c