Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit64eea6c

Browse files
committed
Expand pg_control information so that we can verify that the database
was created on a machine with alignment rules and floating-point formatsimilar to the current machine. Per recent discussion, this seems likea good idea with the increasing prevalence of 32/64 bit environments.
1 parentaa731ed commit64eea6c

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.218 2005/08/22 23:59:04 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.219 2005/10/03 00:28:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -3417,6 +3417,10 @@ WriteControlFile(void)
34173417
*/
34183418
ControlFile->pg_control_version=PG_CONTROL_VERSION;
34193419
ControlFile->catalog_version_no=CATALOG_VERSION_NO;
3420+
3421+
ControlFile->maxAlign=MAXIMUM_ALIGNOF;
3422+
ControlFile->floatFormat=FLOATFORMAT_VALUE;
3423+
34203424
ControlFile->blcksz=BLCKSZ;
34213425
ControlFile->relseg_size=RELSEG_SIZE;
34223426
ControlFile->xlog_seg_size=XLOG_SEG_SIZE;
@@ -3562,6 +3566,18 @@ ReadControlFile(void)
35623566
" but the server was compiled with CATALOG_VERSION_NO %d.",
35633567
ControlFile->catalog_version_no,CATALOG_VERSION_NO),
35643568
errhint("It looks like you need to initdb.")));
3569+
if (ControlFile->maxAlign!=MAXIMUM_ALIGNOF)
3570+
ereport(FATAL,
3571+
(errmsg("database files are incompatible with server"),
3572+
errdetail("The database cluster was initialized with MAXALIGN %d,"
3573+
" but the server was compiled with MAXALIGN %d.",
3574+
ControlFile->maxAlign,MAXIMUM_ALIGNOF),
3575+
errhint("It looks like you need to initdb.")));
3576+
if (ControlFile->floatFormat!=FLOATFORMAT_VALUE)
3577+
ereport(FATAL,
3578+
(errmsg("database files are incompatible with server"),
3579+
errdetail("The database cluster appears to use a different floating-point format than the server executable."),
3580+
errhint("It looks like you need to initdb.")));
35653581
if (ControlFile->blcksz!=BLCKSZ)
35663582
ereport(FATAL,
35673583
(errmsg("database files are incompatible with server"),

‎src/bin/pg_controldata/pg_controldata.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
77
* licence: BSD
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.25 2005/06/08 15:50:27 tgl Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.26 2005/10/03 00:28:41 tgl Exp $
1010
*/
1111
#include"postgres.h"
1212

@@ -168,6 +168,8 @@ main(int argc, char *argv[])
168168
printf(_("Latest checkpoint's NextMultiXactId: %u\n"),ControlFile.checkPointCopy.nextMulti);
169169
printf(_("Latest checkpoint's NextMultiOffset: %u\n"),ControlFile.checkPointCopy.nextMultiOffset);
170170
printf(_("Time of latest checkpoint: %s\n"),ckpttime_str);
171+
printf(_("Maximum data alignment: %u\n"),ControlFile.maxAlign);
172+
/* we don't print floatFormat since can't say much useful about it */
171173
printf(_("Database block size: %u\n"),ControlFile.blcksz);
172174
printf(_("Blocks per segment of large relation: %u\n"),ControlFile.relseg_size);
173175
printf(_("Bytes per WAL segment: %u\n"),ControlFile.xlog_seg_size);

‎src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
2424
* Portions Copyright (c) 1994, Regents of the University of California
2525
*
26-
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.36 2005/09/29 08:34:50 petere Exp $
26+
* $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.37 2005/10/03 00:28:42 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -456,6 +456,8 @@ GuessControlValues(void)
456456
ControlFile.logSeg=1;
457457
ControlFile.checkPoint=ControlFile.checkPointCopy.redo;
458458

459+
ControlFile.maxAlign=MAXIMUM_ALIGNOF;
460+
ControlFile.floatFormat=FLOATFORMAT_VALUE;
459461
ControlFile.blcksz=BLCKSZ;
460462
ControlFile.relseg_size=RELSEG_SIZE;
461463
ControlFile.xlog_seg_size=XLOG_SEG_SIZE;
@@ -523,6 +525,8 @@ PrintControlValues(bool guessed)
523525
printf(_("Latest checkpoint's NextOID: %u\n"),ControlFile.checkPointCopy.nextOid);
524526
printf(_("Latest checkpoint's NextMultiXactId: %u\n"),ControlFile.checkPointCopy.nextMulti);
525527
printf(_("Latest checkpoint's NextMultiOffset: %u\n"),ControlFile.checkPointCopy.nextMultiOffset);
528+
printf(_("Maximum data alignment: %u\n"),ControlFile.maxAlign);
529+
/* we don't print floatFormat since can't say much useful about it */
526530
printf(_("Database block size: %u\n"),ControlFile.blcksz);
527531
printf(_("Blocks per segment of large relation: %u\n"),ControlFile.relseg_size);
528532
printf(_("Maximum length of identifiers: %u\n"),ControlFile.nameDataLen);

‎src/include/catalog/pg_control.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.23 2005/06/08 15:50:28 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.24 2005/10/03 00:28:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,7 +22,7 @@
2222

2323

2424
/* Version identifier for this pg_control format */
25-
#definePG_CONTROL_VERSION811
25+
#definePG_CONTROL_VERSION812
2626

2727
/*
2828
* Body of CheckPoint XLOG records. This is declared here because we keep
@@ -107,6 +107,22 @@ typedef struct ControlFileData
107107

108108
CheckPointcheckPointCopy;/* copy of last check point record */
109109

110+
/*
111+
* This data is used to check for hardware-architecture compatibility
112+
* of the database and the backend executable. We need not check
113+
* endianness explicitly, since the pg_control version will surely
114+
* look wrong to a machine of different endianness, but we do need
115+
* to worry about MAXALIGN and floating-point format. (Note: storage
116+
* layout nominally also depends on SHORTALIGN and INTALIGN, but in
117+
* practice these are the same on all architectures of interest.)
118+
*
119+
* Testing just one double value is not a very bulletproof test for
120+
* floating-point compatibility, but it will catch most cases.
121+
*/
122+
uint32maxAlign;/* alignment requirement for tuples */
123+
doublefloatFormat;/* constant 1234567.0 */
124+
#defineFLOATFORMAT_VALUE1234567.0
125+
110126
/*
111127
* This data is used to make sure that configuration of this database
112128
* is compatible with the backend executable.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp