OSDN Git Service

Prevent lazy_space_alloc from making requests that exceed MaxAllocSize,
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 4 Mar 2006 19:09:09 +0000 (19:09 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 4 Mar 2006 19:09:09 +0000 (19:09 +0000)
per report from Stefan Kaltenbrunner.

src/backend/commands/vacuumlazy.c

index 2c1ba51..5fc251d 100644 (file)
@@ -31,7 +31,7 @@
  *
  *
  * 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/smgr.h"
 #include "utils/lsyscache.h"
+#include "utils/memutils.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 = Min(maxtuples, INT_MAX);
+       maxtuples = Min(maxtuples, MaxAllocSize / sizeof(ItemPointerData));
        /* stay sane if small maintenance_work_mem */
        maxtuples = Max(maxtuples, MaxHeapTuplesPerPage);
 
@@ -966,6 +968,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;