Prevent lazy_space_alloc from making requests that exceed MaxAllocSize,
authorTom Lane <[email protected]>
Sat, 4 Mar 2006 19:09:23 +0000 (19:09 +0000)
committerTom Lane <[email protected]>
Sat, 4 Mar 2006 19:09:23 +0000 (19:09 +0000)
per report from Stefan Kaltenbrunner.

src/backend/commands/vacuumlazy.c

index ecab111e5a9180819bf9404bb28e7d5a5ce944de..9a24d25508506427ef1d56681df52b5e2d4435b4 100644 (file)
@@ -48,6 +48,7 @@
 #include "storage/freespace.h"
 #include "storage/smgr.h"
 #include "utils/lsyscache.h"
+#include "utils/memutils.h"
 #include "utils/pg_rusage.h"
 
 
@@ -955,6 +956,7 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
 
        maxtuples = (maintenance_work_mem * 1024L) / sizeof(ItemPointerData);
        maxtuples = Min(maxtuples, INT_MAX);
+       maxtuples = Min(maxtuples, MaxAllocSize / sizeof(ItemPointerData));
        /* stay sane if small maintenance_work_mem */
        maxtuples = Max(maxtuples, MaxHeapTuplesPerPage);
 
@@ -964,6 +966,7 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
                palloc(maxtuples * sizeof(ItemPointerData));
 
        maxpages = MaxFSMPages;
+       maxpages = Min(maxpages, MaxAllocSize / sizeof(PageFreeSpaceInfo));
        /* No need to allocate more pages than the relation has blocks */
        if (relblocks < (BlockNumber) maxpages)
                maxpages = (int) relblocks;