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

Commit3137b49

Browse files
committed
Fix possible page corruption by ALTER TABLE .. SET TABLESPACE.
If a zeroed page is present in the heap, ALTER TABLE .. SET TABLESPACE willset the LSN and TLI while copying it, which is wrong, and heap_xlog_newpage()will do the same thing during replay, so the corruption propagates to anystandby. Note, however, that the bug can't be demonstrated unless archivingis enabled, since in that case we skip WAL logging altogether, and the LSN/TLIare not set.Back-patch to 8.0; prior releases do not have tablespaces.Analysis and patch by Jeff Davis. Adjustments for back-branches and minorwordsmithing by me.
1 parent5a54266 commit3137b49

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 11 additions & 3 deletions
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.182.4.1 2005/08/25 19:44:52 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.182.4.2 2010/07/29 16:15:47 rhaas Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2304,8 +2304,16 @@ heap_xlog_newpage(bool redo, XLogRecPtr lsn, XLogRecord *record)
23042304
Assert(record->xl_len==SizeOfHeapNewpage+BLCKSZ);
23052305
memcpy(page, (char*)xlrec+SizeOfHeapNewpage,BLCKSZ);
23062306

2307-
PageSetLSN(page,lsn);
2308-
PageSetTLI(page,ThisTimeLineID);
2307+
/*
2308+
* The page may be uninitialized. If so, we can't set the LSN
2309+
* and TLI because that would corrupt the page.
2310+
*/
2311+
if (!PageIsNew(page))
2312+
{
2313+
PageSetLSN(page,lsn);
2314+
PageSetTLI(page,ThisTimeLineID);
2315+
}
2316+
23092317
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
23102318
WriteBuffer(buffer);
23112319
}

‎src/backend/commands/tablecmds.c

Lines changed: 10 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.12 2010/07/01 14:10:42 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.142.4.13 2010/07/29 16:15:47 rhaas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -5786,8 +5786,15 @@ copy_relation_data(Relation rel, SMgrRelation dst)
57865786

57875787
recptr=XLogInsert(RM_HEAP_ID,XLOG_HEAP_NEWPAGE,rdata);
57885788

5789-
PageSetLSN(page,recptr);
5790-
PageSetTLI(page,ThisTimeLineID);
5789+
/*
5790+
* The page may be uninitialized. If so, we can't set the LSN
5791+
* and TLI because that would corrupt the page.
5792+
*/
5793+
if (!PageIsNew(page))
5794+
{
5795+
PageSetLSN(page,recptr);
5796+
PageSetTLI(page,ThisTimeLineID);
5797+
}
57915798

57925799
END_CRIT_SECTION();
57935800
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp