Re: 8.2 pg_freespacemap crash

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dimitri Fontaine <dfontaine(at)hi-media(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: 8.2 pg_freespacemap crash
Date: 2009-04-07 18:13:58
Message-ID: 18785.1239128038@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message John R Pierce 2009-04-07 18:23:25 Re: Backup -- Feridun Türk
Previous Message feridun türk 2009-04-07 18:02:14 Backup -- Feridun Türk