Skip to content

Commit 8e21bf5

Browse files
committed
Fix another longstanding problem in copy_relation_data: it was blithely
assuming that a local char[] array would be aligned on at least a word boundary. There are architectures on which that is pretty much guaranteed to NOT be the case ... and those arches also don't like non-aligned memory accesses, meaning that log_newpage() would crash if it ever got invoked. Even on Intel-ish machines there's a potential for a large performance penalty from doing I/O to an inadequately aligned buffer. So palloc it instead. Backpatch to 8.0 --- 7.4 doesn't have this code.
1 parent 3137b49 commit 8e21bf5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/backend/commands/tablecmds.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.142.4.13 2010/07/29 16:15:47 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.142.4.14 2010/07/29 19:24:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -5729,11 +5729,11 @@ static void
57295729
copy_relation_data(Relation rel, SMgrRelation dst)
57305730
{
57315731
SMgrRelation src;
5732+
char *buf;
5733+
Page page;
57325734
bool use_wal;
57335735
BlockNumber nblocks;
57345736
BlockNumber blkno;
5735-
char buf[BLCKSZ];
5736-
Page page = (Page) buf;
57375737

57385738
/*
57395739
* Since we copy the data directly without looking at the shared
@@ -5744,6 +5744,15 @@ copy_relation_data(Relation rel, SMgrRelation dst)
57445744
*/
57455745
FlushRelationBuffers(rel, 0);
57465746

5747+
/*
5748+
* palloc the buffer so that it's MAXALIGN'd. If it were just a local
5749+
* char[] array, the compiler might align it on any byte boundary, which
5750+
* can seriously hurt transfer speed to and from the kernel; not to
5751+
* mention possibly making PageSetLSN fail.
5752+
*/
5753+
buf = (char *) palloc(BLCKSZ);
5754+
page = (Page) buf;
5755+
57475756
/*
57485757
* We need to log the copied data in WAL iff WAL archiving is enabled
57495758
* AND it's not a temp rel.
@@ -5807,6 +5816,8 @@ copy_relation_data(Relation rel, SMgrRelation dst)
58075816
smgrwrite(dst, blkno, buf, true);
58085817
}
58095818

5819+
pfree(buf);
5820+
58105821
/*
58115822
* If the rel isn't temp, we must fsync it down to disk before it's
58125823
* safe to commit the transaction. (For a temp rel we don't care

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy