From 43fb0a032dfdeb5fb745d2982d5a5f9b55e77d8c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 7 Apr 2009 18:10:56 +0000 Subject: [PATCH] Fix contrib/pg_freespacemap's underestimate of the number of pages it could find in the FSM. Per report from Dimitri Fontaine and Andrew Gierth. (Affects only 8.2 and 8.3 since HEAD no longer has MaxFSMPages at all.) --- contrib/pg_freespacemap/pg_freespacemap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/pg_freespacemap/pg_freespacemap.c b/contrib/pg_freespacemap/pg_freespacemap.c index f17ffbaf20..af6c64c66e 100644 --- a/contrib/pg_freespacemap/pg_freespacemap.c +++ b/contrib/pg_freespacemap/pg_freespacemap.c @@ -94,6 +94,7 @@ pg_freespacemap_pages(PG_FUNCTION_ARGS) 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,7 +103,10 @@ pg_freespacemap_pages(PG_FUNCTION_ARGS) */ FreeSpaceMap = GetFreeSpaceMap(); - numPages = MaxFSMPages; + /* 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(); -- 2.39.5