I wrote:
> Hmm.  Actually the freespace.c code rounds that number up to the next
> multiple of CHUNKPAGES:
>       /* Allocate page-storage arena */
>       nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1;

While that's true, on closer inspection the *real* problem is that
CHUNKPAGES is only correct for heap relations.  Indexes can squeeze 50%
more pages per chunk.  So you probably saw the problem because you have
lots of indexes, not because you were hard up against the roundoff
boundary.

The correct patch is

Index: pg_freespacemap.c
===================================================================
RCS file: /cvsroot/pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v
retrieving revision 1.9
diff -c -r1.9 pg_freespacemap.c
*** pg_freespacemap.c   19 Oct 2006 18:32:46 -0000      1.9
--- pg_freespacemap.c   7 Apr 2009 18:05:23 -0000
***************
*** 94,99 ****
--- 94,100 ----
        if (SRF_IS_FIRSTCALL())
        {
                int                     i;
+               int                     nchunks;        /* Size of 
freespace.c's arena. */
                int                     numPages;       /* Max possible no. of 
pages in map. */
                int                     nPages;         /* Mapped pages for a 
relation. */
  
***************
*** 102,108 ****
                 */
                FreeSpaceMap = GetFreeSpaceMap();
  
!               numPages = MaxFSMPages;
  
                funcctx = SRF_FIRSTCALL_INIT();
  
--- 103,112 ----
                 */
                FreeSpaceMap = GetFreeSpaceMap();
  
!               /* this must match calculation in InitFreeSpaceMap(): */
!               nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1;
!               /* Worst case (lots of indexes) could have this many pages: */
!               numPages = nchunks * INDEXCHUNKPAGES;
  
                funcctx = SRF_FIRSTCALL_INIT();
  


                        regards, tom lane

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to