Commit bc2b85d9 authored by Simon Riggs's avatar Simon Riggs

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.
parent a2c3931a
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/heap/pruneheap.c,v 1.22 2010/02/26 02:00:33 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/heap/pruneheap.c,v 1.23 2010/04/21 17:20:56 sriggs Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -122,8 +122,10 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) ...@@ -122,8 +122,10 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin)
*/ */
if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree) if (PageIsFull(page) || PageGetHeapFreeSpace(page) < minfree)
{ {
TransactionId ignore = InvalidTransactionId; /* return value not needed */
/* OK to prune */ /* OK to prune */
(void) heap_page_prune(relation, buffer, OldestXmin, true); (void) heap_page_prune(relation, buffer, OldestXmin, true, &ignore);
} }
/* And release buffer lock */ /* And release buffer lock */
...@@ -145,11 +147,12 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin) ...@@ -145,11 +147,12 @@ heap_page_prune_opt(Relation relation, Buffer buffer, TransactionId OldestXmin)
* send its own new total to pgstats, and we don't want this delta applied * send its own new total to pgstats, and we don't want this delta applied
* on top of that.) * on top of that.)
* *
* Returns the number of tuples deleted from the page. * Returns the number of tuples deleted from the page and sets
* latestRemovedXid.
*/ */
int int
heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
bool report_stats) bool report_stats, TransactionId *latestRemovedXid)
{ {
int ndeleted = 0; int ndeleted = 0;
Page page = BufferGetPage(buffer); Page page = BufferGetPage(buffer);
...@@ -273,6 +276,8 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, ...@@ -273,6 +276,8 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
if (report_stats && ndeleted > prstate.ndead) if (report_stats && ndeleted > prstate.ndead)
pgstat_update_heap_dead_tuples(relation, ndeleted - prstate.ndead); pgstat_update_heap_dead_tuples(relation, ndeleted - prstate.ndead);
*latestRemovedXid = prstate.latestRemovedXid;
/* /*
* XXX Should we update the FSM information of this page ? * XXX Should we update the FSM information of this page ?
* *
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.132 2010/02/26 02:00:40 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.133 2010/04/21 17:20:56 sriggs Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -274,6 +274,8 @@ vacuum_log_cleanup_info(Relation rel, LVRelStats *vacrelstats) ...@@ -274,6 +274,8 @@ vacuum_log_cleanup_info(Relation rel, LVRelStats *vacrelstats)
if (rel->rd_istemp || !XLogIsNeeded()) if (rel->rd_istemp || !XLogIsNeeded())
return; return;
Assert(TransactionIdIsValid(vacrelstats->latestRemovedXid));
(void) log_heap_cleanup_info(rel->rd_node, vacrelstats->latestRemovedXid); (void) log_heap_cleanup_info(rel->rd_node, vacrelstats->latestRemovedXid);
} }
...@@ -395,9 +397,11 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -395,9 +397,11 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
vacrelstats); vacrelstats);
/* Remove tuples from heap */ /* Remove tuples from heap */
lazy_vacuum_heap(onerel, vacrelstats); lazy_vacuum_heap(onerel, vacrelstats);
/* Forget the now-vacuumed tuples, and press on */ /*
* Forget the now-vacuumed tuples, and press on, but be careful
* not to reset latestRemovedXid since we want that value to be valid.
*/
vacrelstats->num_dead_tuples = 0; vacrelstats->num_dead_tuples = 0;
vacrelstats->latestRemovedXid = InvalidTransactionId;
vacrelstats->num_index_scans++; vacrelstats->num_index_scans++;
} }
...@@ -484,8 +488,8 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -484,8 +488,8 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
* *
* We count tuples removed by the pruning step as removed by VACUUM. * We count tuples removed by the pruning step as removed by VACUUM.
*/ */
tups_vacuumed += heap_page_prune(onerel, buf, OldestXmin, false); tups_vacuumed += heap_page_prune(onerel, buf, OldestXmin, false,
&vacrelstats->latestRemovedXid);
/* /*
* Now scan the page to collect vacuumable items and check for tuples * Now scan the page to collect vacuumable items and check for tuples
* requiring freezing. * requiring freezing.
...@@ -676,9 +680,12 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -676,9 +680,12 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
{ {
/* Remove tuples from heap */ /* Remove tuples from heap */
lazy_vacuum_page(onerel, blkno, buf, 0, vacrelstats); lazy_vacuum_page(onerel, blkno, buf, 0, vacrelstats);
/* Forget the now-vacuumed tuples, and press on */ /*
* Forget the now-vacuumed tuples, and press on, but be careful
* not to reset latestRemovedXid since we want that value to be valid.
*/
Assert(TransactionIdIsValid(vacrelstats->latestRemovedXid));
vacrelstats->num_dead_tuples = 0; vacrelstats->num_dead_tuples = 0;
vacrelstats->latestRemovedXid = InvalidTransactionId;
vacuumed_pages++; vacuumed_pages++;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.148 2010/02/26 02:01:20 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/heapam.h,v 1.149 2010/04/21 17:20:56 sriggs Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -144,7 +144,7 @@ extern void heap_page_prune_opt(Relation relation, Buffer buffer, ...@@ -144,7 +144,7 @@ extern void heap_page_prune_opt(Relation relation, Buffer buffer,
TransactionId OldestXmin); TransactionId OldestXmin);
extern int heap_page_prune(Relation relation, Buffer buffer, extern int heap_page_prune(Relation relation, Buffer buffer,
TransactionId OldestXmin, TransactionId OldestXmin,
bool report_stats); bool report_stats, TransactionId *latestRemovedXid);
extern void heap_page_prune_execute(Buffer buffer, extern void heap_page_prune_execute(Buffer buffer,
OffsetNumber *redirected, int nredirected, OffsetNumber *redirected, int nredirected,
OffsetNumber *nowdead, int ndead, OffsetNumber *nowdead, int ndead,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment