Prevent lazy_space_alloc from making requests that exceed MaxAllocSize,

per report from Stefan Kaltenbrunner.
This commit is contained in:
Tom Lane 2006-03-04 19:09:09 +00:00
parent 80cadb303c
commit 20bdc71369

View File

@ -31,7 +31,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.66 2006/02/11 23:31:34 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.67 2006/03/04 19:09:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -48,6 +48,7 @@
#include "storage/freespace.h" #include "storage/freespace.h"
#include "storage/smgr.h" #include "storage/smgr.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_rusage.h" #include "utils/pg_rusage.h"
@ -957,6 +958,7 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
maxtuples = (maintenance_work_mem * 1024L) / sizeof(ItemPointerData); maxtuples = (maintenance_work_mem * 1024L) / sizeof(ItemPointerData);
maxtuples = Min(maxtuples, INT_MAX); maxtuples = Min(maxtuples, INT_MAX);
maxtuples = Min(maxtuples, MaxAllocSize / sizeof(ItemPointerData));
/* stay sane if small maintenance_work_mem */ /* stay sane if small maintenance_work_mem */
maxtuples = Max(maxtuples, MaxHeapTuplesPerPage); maxtuples = Max(maxtuples, MaxHeapTuplesPerPage);
@ -966,6 +968,7 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
palloc(maxtuples * sizeof(ItemPointerData)); palloc(maxtuples * sizeof(ItemPointerData));
maxpages = MaxFSMPages; maxpages = MaxFSMPages;
maxpages = Min(maxpages, MaxAllocSize / sizeof(PageFreeSpaceInfo));
/* No need to allocate more pages than the relation has blocks */ /* No need to allocate more pages than the relation has blocks */
if (relblocks < (BlockNumber) maxpages) if (relblocks < (BlockNumber) maxpages)
maxpages = (int) relblocks; maxpages = (int) relblocks;