Skip to content

Commit bc2b85d

Browse files
Fix oversight in collecting values for cleanup_info records.
vacuum_log_cleanup_info() now generates log records with a valid latestRemovedXid set in all cases. Also be careful not to zero the value when we do a round of vacuuming part-way through lazy_scan_heap(). Incidentally, this reduces frequency of conflicts in Hot Standby.
1 parent a2c3931 commit bc2b85d

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/backend/access/heap/pruneheap.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/pruneheap.c,v 1.22 2010/02/26 02:00:33 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/pruneheap.c,v 1.23 2010/04/21 17:20:56 sriggs Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -122,8 +122,10 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin)
122122
*/
123123
if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree)
124124
{
125+
TransactionId ignore = InvalidTransactionId; /* return value not needed */
126+
125127
/* OK to prune */
126-
(void) heap_page_prune(relation, buffer, OldestXmin, true);
128+
(void) heap_page_prune(relation, buffer, OldestXmin, true, &ignore);
127129
}
128130

129131
/* And release buffer lock */
@@ -145,11 +147,12 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin)
145147
* send its own new total to pgstats, and we don't want this delta applied
146148
* on top of that.)
147149
*
148-
* Returns the number of tuples deleted from the page.
150+
* Returns the number of tuples deleted from the page and sets
151+
* latestRemovedXid.
149152
*/
150153
int
151154
heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
152-
bool report_stats)
155+
bool report_stats, TransactionId *latestRemovedXid)
153156
{
154157
int ndeleted = 0;
155158
Page page = BufferGetPage(buffer);
@@ -273,6 +276,8 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
273276
if (report_stats && ndeleted > prstate.ndead)
274277
pgstat_update_heap_dead_tuples(relation, ndeleted - prstate.ndead);
275278

279+
*latestRemovedXid = prstate.latestRemovedXid;
280+
276281
/*
277282
* XXX Should we update the FSM information of this page ?
278283
*

src/backend/commands/vacuumlazy.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
*
3131
* IDENTIFICATION
32-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.132 2010/02/26 02:00:40 momjian Exp $
32+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.133 2010/04/21 17:20:56 sriggs Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -274,6 +274,8 @@ vacuum_log_cleanup_info(Relation rel, LVRelStats *vacrelstats)
274274
if (rel->rd_istemp || !XLogIsNeeded())
275275
return;
276276

277+
Assert(TransactionIdIsValid(vacrelstats->latestRemovedXid));
278+
277279
(void) log_heap_cleanup_info(rel->rd_node, vacrelstats->latestRemovedXid);
278280
}
279281

@@ -395,9 +397,11 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
395397
vacrelstats);
396398
/* Remove tuples from heap */
397399
lazy_vacuum_heap(onerel, vacrelstats);
398-
/* Forget the now-vacuumed tuples, and press on */
400+
/*
401+
* Forget the now-vacuumed tuples, and press on, but be careful
402+
* not to reset latestRemovedXid since we want that value to be valid.
403+
*/
399404
vacrelstats->num_dead_tuples = 0;
400-
vacrelstats->latestRemovedXid = InvalidTransactionId;
401405
vacrelstats->num_index_scans++;
402406
}
403407

@@ -484,8 +488,8 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
484488
*
485489
* We count tuples removed by the pruning step as removed by VACUUM.
486490
*/
487-
tups_vacuumed += heap_page_prune(onerel, buf, OldestXmin, false);
488-
491+
tups_vacuumed += heap_page_prune(onerel, buf, OldestXmin, false,
492+
&vacrelstats->latestRemovedXid);
489493
/*
490494
* Now scan the page to collect vacuumable items and check for tuples
491495
* requiring freezing.
@@ -676,9 +680,12 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
676680
{
677681
/* Remove tuples from heap */
678682
lazy_vacuum_page(onerel, blkno, buf, 0, vacrelstats);
679-
/* Forget the now-vacuumed tuples, and press on */
683+
/*
684+
* Forget the now-vacuumed tuples, and press on, but be careful
685+
* not to reset latestRemovedXid since we want that value to be valid.
686+
*/
687+
Assert(TransactionIdIsValid(vacrelstats->latestRemovedXid));
680688
vacrelstats->num_dead_tuples = 0;
681-
vacrelstats->latestRemovedXid = InvalidTransactionId;
682689
vacuumed_pages++;
683690
}
684691

src/include/access/heapam.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.148 2010/02/26 02:01:20 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.149 2010/04/21 17:20:56 sriggs Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -144,7 +144,7 @@ extern void heap_page_prune_opt(Relation relation, Buffer buffer,
144144
TransactionId OldestXmin);
145145
extern int heap_page_prune(Relation relation, Buffer buffer,
146146
TransactionId OldestXmin,
147-
bool report_stats);
147+
bool report_stats, TransactionId *latestRemovedXid);
148148
extern void heap_page_prune_execute(Buffer buffer,
149149
OffsetNumber *redirected, int nredirected,
150150
OffsetNumber *nowdead, int ndead,

0 commit comments

Comments
 (0)