Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e55e6ec

Browse files
committed
Fix replay of XLOG_HEAP_NEWPAGE WAL records to pay attention to the forknum
field of the WAL record. The previous coding always wrote to the main fork, resulting in data corruption if the page was meant to go into a non-default fork. At present, the only operation that can produce such WAL records is ALTER TABLE/INDEX SET TABLESPACE when executed with archive_mode = on. Data corruption would be observed on standby slaves, and could occur on the master as well if a database crash and recovery occurred after committing the ALTER and before the next checkpoint. Per report from Gordon Shannon. Back-patch to 8.4; the problem doesn't exist in earlier branches because we didn't have a concept of multiple relation forks then.
1 parent 3a0939e commit e55e6ec

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/backend/access/heap/heapam.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.289 2010/04/22 02:15:45 sriggs Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.290 2010/05/02 22:28:05 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -4257,8 +4257,10 @@ heap_xlog_newpage(XLogRecPtr lsn, XLogRecord *record)
42574257
* Note: the NEWPAGE log record is used for both heaps and indexes, so do
42584258
* not do anything that assumes we are touching a heap.
42594259
*/
4260-
buffer = XLogReadBuffer(xlrec->node, xlrec->blkno, true);
4260+
buffer = XLogReadBufferExtended(xlrec->node, xlrec->forknum, xlrec->blkno,
4261+
RBM_ZERO);
42614262
Assert(BufferIsValid(buffer));
4263+
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
42624264
page = (Page) BufferGetPage(buffer);
42634265

42644266
Assert(record->xl_len == SizeOfHeapNewpage + BLCKSZ);

0 commit comments

Comments
 (0)