Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 12:00 AM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: TODO Item - Add system view to show free space map

Want to host it on pgfoundry until 8.2 is released?

Mark Kirkwood wrote:
> This patch implements a view to display the free space map contents - e.g :
>
> regression=# SELECT c.relname, m.relblocknumber, m.blockfreebytes
> FROM pg_freespacemap m INNER JOIN pg_class c
> ON c.relfilenode = m.relfilenode LIMIT 10;
> relname | relblocknumber | blockfreebytes
> ------------------------+----------------+----------------
> sql_features | 5 | 2696
> sql_implementation_info | 0 | 7104
> sql_languages | 0 | 8016
> sql_packages | 0 | 7376
> sql_sizing | 0 | 6032
> pg_authid | 0 | 7424
> pg_toast_2618 | 13 | 4588
> pg_toast_2618 | 12 | 1680
> pg_toast_2618 | 10 | 1436
> pg_toast_2618 | 7 | 1136
> (10 rows)
>
> [I found being able to display the FSM pretty cool, even if I say so
> myself....].
>
> It is written as a contrib module (similar to pg_buffercache) so as to
> make any revisions non-initdb requiring.
>
> The code needs to know about several of the (currently) internal data
> structures in freespace.c, so I moved these into freespace.h. Similarly
> for the handy macros to actually compute the free space. Let me know if
> this was the wrong way to proceed!
>
> Additionally access to the FSM pointer itself is required, I added a
> function in freespace.c to return this, rather than making it globally
> visible, again if the latter is a better approach, it is easily changed.
>
> cheers
>
> Mark
>
> P.s : Currently don't have access to a windows box, so had to just 'take
> a stab' at what DLLIMPORTs were required.
>
>
>
> ------------------------------------------------------------------------
>
> diff -Ncar pgsql.orig/contrib/pg_freespacemap/Makefile pgsql/contrib/pg_freespacemap/Makefile
> *** pgsql.orig/contrib/pg_freespacemap/Makefile Thu Jan 1 12:00:00 1970
> --- pgsql/contrib/pg_freespacemap/Makefile Thu Oct 27 17:52:10 2005
> ***************
> *** 0 ****
> --- 1,17 ----
> + # $PostgreSQL$
> +
> + MODULE_big = pg_freespacemap
> + OBJS = pg_freespacemap.o
> +
> + DATA_built = pg_freespacemap.sql
> + DOCS = README.pg_freespacemap
> +
> + ifdef USE_PGXS
> + PGXS := $(shell pg_config --pgxs)
> + include $(PGXS)
> + else
> + subdir = contrib/pg_freespacemap
> + top_builddir = ../..
> + include $(top_builddir)/src/Makefile.global
> + include $(top_srcdir)/contrib/contrib-global.mk
> + endif
> diff -Ncar pgsql.orig/contrib/pg_freespacemap/README.pg_freespacemap pgsql/contrib/pg_freespacemap/README.pg_freespacemap
> *** pgsql.orig/contrib/pg_freespacemap/README.pg_freespacemap Thu Jan 1 12:00:00 1970
> --- pgsql/contrib/pg_freespacemap/README.pg_freespacemap Thu Oct 27 18:06:20 2005
> ***************
> *** 0 ****
> --- 1,98 ----
> + Pg_freespacemap - Real time queries on the free space map (FSM).
> + ---------------
> +
> + This module consists of a C function 'pg_freespacemap()' that returns
> + a set of records, and a view 'pg_freespacemap' to wrapper the function.
> +
> + The module provides the ability to examine the contents of the free space
> + map, without having to restart or rebuild the server with additional
> + debugging code.
> +
> + By default public access is REVOKED from both of these, just in case there
> + are security issues lurking.
> +
> +
> + Installation
> + ------------
> +
> + Build and install the main Postgresql source, then this contrib module:
> +
> + $ cd contrib/pg_freespacemap
> + $ gmake
> + $ gmake install
> +
> +
> + To register the functions:
> +
> + $ psql -d <database> -f pg_freespacemap.sql
> +
> +
> + Notes
> + -----
> +
> + The definition of the columns exposed in the view is:
> +
> + Column | references | Description
> + ----------------+----------------------+------------------------------------
> + blockid | | Id, 1.. max_fsm_pages
> + relfilenode | pg_class.relfilenode | Refilenode of the relation.
> + reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
> + reldatabase | pg_database.oid | Database for the relation.
> + relblocknumber | | Offset of the page in the relation.
> + blockfreebytes | | Free bytes in the block/page.
> +
> +
> + There is one row for each page in the free space map.
> +
> + Because the map is shared by all the databases, there are pages from
> + relations not belonging to the current database.
> +
> + When the pg_freespacemap view is accessed, internal free space map locks are
> + taken, and a copy of the map data is made for the view to display.
> + This ensures that the view produces a consistent set of results, while not
> + blocking normal activity longer than necessary. Nonetheless there
> + could be some impact on database performance if this view is read often.
> +
> +
> + Sample output
> + -------------
> +
> + regression=# \d pg_freespacemap
> + View "public.pg_freespacemap"
> + Column | Type | Modifiers
> + ---------------+---------+-----------
> + blockid | integer |
> + relfilenode | oid |
> + reltablespace | oid |
> + reldatabase | oid |
> + relblocknumber | bigint |
> + blockfreebytes | integer |
> + View definition:
> + SELECT p.blockid, p.relfilenode, p.reltablespace, p.reldatabase, p.relblocknumber, p.blockfreebytes
> + FROM pg_freespacemap() p(blockid integer, relfilenode oid, reltablespace oid, reldatabase oid, relblocknumber bigint, blockfreebytes integer);
> +
> + regression=# SELECT c.relname, m.relblocknumber, m.blockfreebytes
> + FROM pg_freespacemap m INNER JOIN pg_class c
> + ON c.relfilenode = m.relfilenode LIMIT 10;
> + relname | relblocknumber | blockfreebytes
> + ------------------------+----------------+----------------
> + sql_features | 5 | 2696
> + sql_implementation_info | 0 | 7104
> + sql_languages | 0 | 8016
> + sql_packages | 0 | 7376
> + sql_sizing | 0 | 6032
> + pg_authid | 0 | 7424
> + pg_toast_2618 | 13 | 4588
> + pg_toast_2618 | 12 | 1680
> + pg_toast_2618 | 10 | 1436
> + pg_toast_2618 | 7 | 1136
> + (10 rows)
> +
> + regression=#
> +
> +
> + Author
> + ------
> +
> + * Mark Kirkwood <markir@paradise.net.nz>
> +
> diff -Ncar pgsql.orig/contrib/pg_freespacemap/pg_freespacemap.c pgsql/contrib/pg_freespacemap/pg_freespacemap.c
> *** pgsql.orig/contrib/pg_freespacemap/pg_freespacemap.c Thu Jan 1 12:00:00 1970
> --- pgsql/contrib/pg_freespacemap/pg_freespacemap.c Thu Oct 27 18:07:05 2005
> ***************
> *** 0 ****
> --- 1,231 ----
> + /*-------------------------------------------------------------------------
> + *
> + * pg_freespacemap.c
> + * display some contents of the free space map.
> + *
> + * $PostgreSQL$
> + *-------------------------------------------------------------------------
> + */
> + #include "postgres.h"
> + #include "funcapi.h"
> + #include "catalog/pg_type.h"
> + #include "storage/freespace.h"
> + #include "utils/relcache.h"
> +
> + #define NUM_FREESPACE_PAGES_ELEM 6
> +
> + #if defined(WIN32) || defined(__CYGWIN__)
> + extern DLLIMPORT volatile uint32 InterruptHoldoffCount;
> + #endif
> +
> + Datum pg_freespacemap(PG_FUNCTION_ARGS);
> +
> +
> + /*
> + * Record structure holding the to be exposed free space data.
> + */
> + typedef struct
> + {
> +
> + uint32 blockid;
> + uint32 relfilenode;
> + uint32 reltablespace;
> + uint32 reldatabase;
> + uint32 relblocknumber;
> + uint32 blockfreebytes;
> +
> + } FreeSpacePagesRec;
> +
> +
> + /*
> + * Function context for data persisting over repeated calls.
> + */
> + typedef struct
> + {
> +
> + AttInMetadata *attinmeta;
> + FreeSpacePagesRec *record;
> + char *values[NUM_FREESPACE_PAGES_ELEM];
> +
> + } FreeSpacePagesContext;
> +
> +
> + /*
> + * Function returning data from the Free Space Map (FSM).
> + */
> + PG_FUNCTION_INFO_V1(pg_freespacemap);
> + Datum
> + pg_freespacemap(PG_FUNCTION_ARGS)
> + {
> +
> + FuncCallContext *funcctx;
> + Datum result;
> + MemoryContext oldcontext;
> + FreeSpacePagesContext *fctx; /* User function context. */
> + TupleDesc tupledesc;
> + HeapTuple tuple;
> +
> + FSMHeader *FreeSpaceMap; /* FSM main structure. */
> + FSMRelation *fsmrel; /* Individual relation. */
> +
> +
> + if (SRF_IS_FIRSTCALL())
> + {
> + uint32 i;
> + uint32 numPages; /* Max possible no. of pages in map. */
> + int nPages; /* Mapped pages for a relation. */
> +
> + /*
> + * Get the free space map data structure.
> + */
> + FreeSpaceMap = GetFreeSpaceMap();
> +
> + numPages = MaxFSMPages;
> +
> + funcctx = SRF_FIRSTCALL_INIT();
> +
> + /* Switch context when allocating stuff to be used in later calls */
> + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
> +
> + /* Construct a tuple to return. */
> + tupledesc = CreateTemplateTupleDesc(NUM_FREESPACE_PAGES_ELEM, false);
> + TupleDescInitEntry(tupledesc, (AttrNumber) 1, "blockid",
> + INT4OID, -1, 0);
> + TupleDescInitEntry(tupledesc, (AttrNumber) 2, "relfilenode",
> + OIDOID, -1, 0);
> + TupleDescInitEntry(tupledesc, (AttrNumber) 3, "reltablespace",
> + OIDOID, -1, 0);
> + TupleDescInitEntry(tupledesc, (AttrNumber) 4, "reldatabase",
> + OIDOID, -1, 0);
> + TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relblocknumber",
> + INT8OID, -1, 0);
> + TupleDescInitEntry(tupledesc, (AttrNumber) 6, "blockfreebytes",
> + INT4OID, -1, 0);
> +
> + /* Generate attribute metadata needed later to produce tuples */
> + funcctx->attinmeta = TupleDescGetAttInMetadata(tupledesc);
> +
> + /*
> + * Create a function context for cross-call persistence and initialize
> + * the counters.
> + */
> + fctx = (FreeSpacePagesContext *) palloc(sizeof(FreeSpacePagesContext));
> + funcctx->user_fctx = fctx;
> +
> + /* Set an upper bound on the calls */
> + funcctx->max_calls = numPages;
> +
> +
> + /* Allocate numPages worth of FreeSpacePagesRec records, this is also
> + * an upper bound.
> + */
> + fctx->record = (FreeSpacePagesRec *) palloc(sizeof(FreeSpacePagesRec) * numPages);
> +
> + /* allocate the strings for tuple formation */
> + fctx->values[0] = (char *) palloc(3 * sizeof(uint32) + 1);
> + fctx->values[1] = (char *) palloc(3 * sizeof(uint32) + 1);
> + fctx->values[2] = (char *) palloc(3 * sizeof(uint32) + 1);
> + fctx->values[3] = (char *) palloc(3 * sizeof(uint32) + 1);
> + fctx->values[4] = (char *) palloc(3 * sizeof(uint32) + 1);
> + fctx->values[5] = (char *) palloc(3 * sizeof(uint32) + 1);
> +
> +
> + /* Return to original context when allocating transient memory */
> + MemoryContextSwitchTo(oldcontext);
> +
> +
> + /*
> + * Lock free space map and scan though all the relations,
> + * for each relation, gets all its mapped pages.
> + */
> + LWLockAcquire(FreeSpaceLock, LW_EXCLUSIVE);
> +
> +
> + i = 0;
> +
> + for (fsmrel = FreeSpaceMap->usageList; fsmrel; fsmrel = fsmrel->nextUsage)
> + {
> +
> + if (fsmrel->isIndex)
> + { /* Index relation. */
> + IndexFSMPageData *page;
> +
> + page = (IndexFSMPageData *)
> + (FreeSpaceMap->arena + fsmrel->firstChunk * CHUNKBYTES);
> +
> + for (nPages = 0; nPages < fsmrel->storedPages; nPages++)
> + {
> +
> + fctx->record[i].blockid = i;
> + fctx->record[i].relfilenode = fsmrel->key.relNode;
> + fctx->record[i].reltablespace = fsmrel->key.spcNode;
> + fctx->record[i].reldatabase = fsmrel->key.dbNode;
> + fctx->record[i].relblocknumber = IndexFSMPageGetPageNum(page);
> + fctx->record[i].blockfreebytes = 0; /* index.*/
> +
> + page++;
> + i++;
> + }
> + }
> + else
> + { /* Heap relation. */
> + FSMPageData *page;
> +
> + page = (FSMPageData *)
> + (FreeSpaceMap->arena + fsmrel->firstChunk * CHUNKBYTES);
> +
> + for (nPages = 0; nPages < fsmrel->storedPages; nPages++)
> + {
> + fctx->record[i].blockid = i;
> + fctx->record[i].relfilenode = fsmrel->key.relNode;
> + fctx->record[i].reltablespace = fsmrel->key.spcNode;
> + fctx->record[i].reldatabase = fsmrel->key.dbNode;
> + fctx->record[i].relblocknumber = FSMPageGetPageNum(page);
> + fctx->record[i].blockfreebytes = FSMPageGetSpace(page);
> +
> + page++;
> + i++;
> + }
> +
> + }
> +
> + }
> +
> + /* Set the real no. of calls as we know it now! */
> + funcctx->max_calls = i;
> +
> + /* Release free space map. */
> + LWLockRelease(FreeSpaceLock);
> + }
> +
> + funcctx = SRF_PERCALL_SETUP();
> +
> + /* Get the saved state */
> + fctx = funcctx->user_fctx;
> +
> +
> + if (funcctx->call_cntr < funcctx->max_calls)
> + {
> + uint32 i = funcctx->call_cntr;
> +
> +
> + sprintf(fctx->values[0], "%u", fctx->record[i].blockid);
> + sprintf(fctx->values[1], "%u", fctx->record[i].relfilenode);
> + sprintf(fctx->values[2], "%u", fctx->record[i].reltablespace);
> + sprintf(fctx->values[3], "%u", fctx->record[i].reldatabase);
> + sprintf(fctx->values[4], "%u", fctx->record[i].relblocknumber);
> + sprintf(fctx->values[5], "%u", fctx->record[i].blockfreebytes);
> +
> +
> +
> + /* Build and return the tuple. */
> + tuple = BuildTupleFromCStrings(funcctx->attinmeta, fctx->values);
> + result = HeapTupleGetDatum(tuple);
> +
> +
> + SRF_RETURN_NEXT(funcctx, result);
> + }
> + else
> + SRF_RETURN_DONE(funcctx);
> +
> + }
> diff -Ncar pgsql.orig/contrib/pg_freespacemap/pg_freespacemap.sql.in pgsql/contrib/pg_freespacemap/pg_freespacemap.sql.in
> *** pgsql.orig/contrib/pg_freespacemap/pg_freespacemap.sql.in Thu Jan 1 12:00:00 1970
> --- pgsql/contrib/pg_freespacemap/pg_freespacemap.sql.in Thu Oct 27 18:07:43 2005
> ***************
> *** 0 ****
> --- 1,17 ----
> + -- Adjust this setting to control where the objects get created.
> + SET search_path = public;
> +
> + -- Register the function.
> + CREATE OR REPLACE FUNCTION pg_freespacemap()
> + RETURNS SETOF RECORD
> + AS 'MODULE_PATHNAME', 'pg_freespacemap'
> + LANGUAGE 'C';
> +
> + -- Create a view for convenient access.
> + CREATE VIEW pg_freespacemap AS
> + SELECT P.* FROM pg_freespacemap() AS P
> + (blockid int4, relfilenode oid, reltablespace oid, reldatabase oid, relblocknumber int8, blockfreebytes int4);
> +
> + -- Don't want these to be available at public.
> + REVOKE ALL ON FUNCTION pg_freespacemap() FROM PUBLIC;
> + REVOKE ALL ON pg_freespacemap FROM PUBLIC;
> diff -Ncar pgsql.orig/src/backend/storage/freespace/freespace.c pgsql/src/backend/storage/freespace/freespace.c
> *** pgsql.orig/src/backend/storage/freespace/freespace.c Thu Oct 20 12:25:06 2005
> --- pgsql/src/backend/storage/freespace/freespace.c Thu Oct 27 17:51:33 2005
> ***************
> *** 71,114 ****
> #include "storage/shmem.h"
>
>
> - /* Initial value for average-request moving average */
> - #define INITIAL_AVERAGE ((Size) (BLCKSZ / 32))
> -
> - /*
> - * Number of pages and bytes per allocation chunk. Indexes can squeeze 50%
> - * more pages into the same space because they don't need to remember how much
> - * free space on each page. The nominal number of pages, CHUNKPAGES, is for
> - * regular rels, and INDEXCHUNKPAGES is for indexes. CHUNKPAGES should be
> - * even so that no space is wasted in the index case.
> - */
> - #define CHUNKPAGES 16
> - #define CHUNKBYTES (CHUNKPAGES * sizeof(FSMPageData))
> - #define INDEXCHUNKPAGES ((int) (CHUNKBYTES / sizeof(IndexFSMPageData)))
> -
> -
> - /*
> - * Typedefs and macros for items in the page-storage arena. We use the
> - * existing ItemPointer and BlockId data structures, which are designed
> - * to pack well (they should be 6 and 4 bytes apiece regardless of machine
> - * alignment issues). Unfortunately we can't use the ItemPointer access
> - * macros, because they include Asserts insisting that ip_posid != 0.
> - */
> - typedef ItemPointerData FSMPageData;
> - typedef BlockIdData IndexFSMPageData;
> -
> - #define FSMPageGetPageNum(ptr) \
> - BlockIdGetBlockNumber(&(ptr)->ip_blkid)
> - #define FSMPageGetSpace(ptr) \
> - ((Size) (ptr)->ip_posid)
> - #define FSMPageSetPageNum(ptr, pg) \
> - BlockIdSet(&(ptr)->ip_blkid, pg)
> - #define FSMPageSetSpace(ptr, sz) \
> - ((ptr)->ip_posid = (OffsetNumber) (sz))
> - #define IndexFSMPageGetPageNum(ptr) \
> - BlockIdGetBlockNumber(ptr)
> - #define IndexFSMPageSetPageNum(ptr, pg) \
> - BlockIdSet(ptr, pg)
> -
> /*----------
> * During database shutdown, we store the contents of FSM into a disk file,
> * which is re-read during startup. This way we don't have a startup
> --- 71,76 ----
> ***************
> *** 156,218 ****
> int32 storedPages; /* # of pages stored in arena */
> } FsmCacheRelHeader;
>
> -
> - /*
> - * Shared free-space-map objects
> - *
> - * The per-relation objects are indexed by a hash table, and are also members
> - * of two linked lists: one ordered by recency of usage (most recent first),
> - * and the other ordered by physical location of the associated storage in
> - * the page-info arena.
> - *
> - * Each relation owns one or more chunks of per-page storage in the "arena".
> - * The chunks for each relation are always consecutive, so that it can treat
> - * its page storage as a simple array. We further insist that its page data
> - * be ordered by block number, so that binary search is possible.
> - *
> - * Note: we handle pointers to these items as pointers, not as SHMEM_OFFSETs.
> - * This assumes that all processes accessing the map will have the shared
> - * memory segment mapped at the same place in their address space.
> - */
> - typedef struct FSMHeader FSMHeader;
> - typedef struct FSMRelation FSMRelation;
> -
> - /* Header for whole map */
> - struct FSMHeader
> - {
> - FSMRelation *usageList; /* FSMRelations in usage-recency order */
> - FSMRelation *usageListTail; /* tail of usage-recency list */
> - FSMRelation *firstRel; /* FSMRelations in arena storage order */
> - FSMRelation *lastRel; /* tail of storage-order list */
> - int numRels; /* number of FSMRelations now in use */
> - double sumRequests; /* sum of requested chunks over all rels */
> - char *arena; /* arena for page-info storage */
> - int totalChunks; /* total size of arena, in chunks */
> - int usedChunks; /* # of chunks assigned */
> - /* NB: there are totalChunks - usedChunks free chunks at end of arena */
> - };
> -
> - /*
> - * Per-relation struct --- this is an entry in the shared hash table.
> - * The hash key is the RelFileNode value (hence, we look at the physical
> - * relation ID, not the logical ID, which is appropriate).
> - */
> - struct FSMRelation
> - {
> - RelFileNode key; /* hash key (must be first) */
> - FSMRelation *nextUsage; /* next rel in usage-recency order */
> - FSMRelation *priorUsage; /* prior rel in usage-recency order */
> - FSMRelation *nextPhysical; /* next rel in arena-storage order */
> - FSMRelation *priorPhysical; /* prior rel in arena-storage order */
> - bool isIndex; /* if true, we store only page numbers */
> - Size avgRequest; /* moving average of space requests */
> - int lastPageCount; /* pages passed to RecordRelationFreeSpace */
> - int firstChunk; /* chunk # of my first chunk in arena */
> - int storedPages; /* # of pages stored in arena */
> - int nextPage; /* index (from 0) to start next search at */
> - };
> -
> -
> int MaxFSMRelations; /* these are set by guc.c */
> int MaxFSMPages;
>
> --- 118,123 ----
> ***************
> *** 1835,1840 ****
> --- 1740,1756 ----
> Assert(fsmrel->firstChunk < 0 && fsmrel->storedPages == 0);
> return 0;
> }
> + }
> +
> +
> + /*
> + * Return the FreeSpaceMap structure for examination.
> + */
> + FSMHeader *
> + GetFreeSpaceMap(void)
> + {
> +
> + return FreeSpaceMap;
> }
>
>
> diff -Ncar pgsql.orig/src/include/storage/freespace.h pgsql/src/include/storage/freespace.h
> *** pgsql.orig/src/include/storage/freespace.h Tue Aug 23 15:56:23 2005
> --- pgsql/src/include/storage/freespace.h Thu Oct 27 17:51:33 2005
> ***************
> *** 16,21 ****
> --- 16,22 ----
>
> #include "storage/block.h"
> #include "storage/relfilenode.h"
> + #include "storage/itemptr.h"
>
>
> /*
> ***************
> *** 28,33 ****
> --- 29,129 ----
> } PageFreeSpaceInfo;
>
>
> + /* Initial value for average-request moving average */
> + #define INITIAL_AVERAGE ((Size) (BLCKSZ / 32))
> +
> + /*
> + * Number of pages and bytes per allocation chunk. Indexes can squeeze 50%
> + * more pages into the same space because they don't need to remember how much
> + * free space on each page. The nominal number of pages, CHUNKPAGES, is for
> + * regular rels, and INDEXCHUNKPAGES is for indexes. CHUNKPAGES should be
> + * even so that no space is wasted in the index case.
> + */
> + #define CHUNKPAGES 16
> + #define CHUNKBYTES (CHUNKPAGES * sizeof(FSMPageData))
> + #define INDEXCHUNKPAGES ((int) (CHUNKBYTES / sizeof(IndexFSMPageData)))
> +
> +
> + /*
> + * Typedefs and macros for items in the page-storage arena. We use the
> + * existing ItemPointer and BlockId data structures, which are designed
> + * to pack well (they should be 6 and 4 bytes apiece regardless of machine
> + * alignment issues). Unfortunately we can't use the ItemPointer access
> + * macros, because they include Asserts insisting that ip_posid != 0.
> + */
> + typedef ItemPointerData FSMPageData;
> + typedef BlockIdData IndexFSMPageData;
> +
> + #define FSMPageGetPageNum(ptr) \
> + BlockIdGetBlockNumber(&(ptr)->ip_blkid)
> + #define FSMPageGetSpace(ptr) \
> + ((Size) (ptr)->ip_posid)
> + #define FSMPageSetPageNum(ptr, pg) \
> + BlockIdSet(&(ptr)->ip_blkid, pg)
> + #define FSMPageSetSpace(ptr, sz) \
> + ((ptr)->ip_posid = (OffsetNumber) (sz))
> + #define IndexFSMPageGetPageNum(ptr) \
> + BlockIdGetBlockNumber(ptr)
> + #define IndexFSMPageSetPageNum(ptr, pg) \
> + BlockIdSet(ptr, pg)
> +
> + /*
> + * Shared free-space-map objects
> + *
> + * The per-relation objects are indexed by a hash table, and are also members
> + * of two linked lists: one ordered by recency of usage (most recent first),
> + * and the other ordered by physical location of the associated storage in
> + * the page-info arena.
> + *
> + * Each relation owns one or more chunks of per-page storage in the "arena".
> + * The chunks for each relation are always consecutive, so that it can treat
> + * its page storage as a simple array. We further insist that its page data
> + * be ordered by block number, so that binary search is possible.
> + *
> + * Note: we handle pointers to these items as pointers, not as SHMEM_OFFSETs.
> + * This assumes that all processes accessing the map will have the shared
> + * memory segment mapped at the same place in their address space.
> + */
> + typedef struct FSMHeader FSMHeader;
> + typedef struct FSMRelation FSMRelation;
> +
> + /* Header for whole map */
> + struct FSMHeader
> + {
> + FSMRelation *usageList; /* FSMRelations in usage-recency order */
> + FSMRelation *usageListTail; /* tail of usage-recency list */
> + FSMRelation *firstRel; /* FSMRelations in arena storage order */
> + FSMRelation *lastRel; /* tail of storage-order list */
> + int numRels; /* number of FSMRelations now in use */
> + double sumRequests; /* sum of requested chunks over all rels */
> + char *arena; /* arena for page-info storage */
> + int totalChunks; /* total size of arena, in chunks */
> + int usedChunks; /* # of chunks assigned */
> + /* NB: there are totalChunks - usedChunks free chunks at end of arena */
> + };
> +
> + /*
> + * Per-relation struct --- this is an entry in the shared hash table.
> + * The hash key is the RelFileNode value (hence, we look at the physical
> + * relation ID, not the logical ID, which is appropriate).
> + */
> + struct FSMRelation
> + {
> + RelFileNode key; /* hash key (must be first) */
> + FSMRelation *nextUsage; /* next rel in usage-recency order */
> + FSMRelation *priorUsage; /* prior rel in usage-recency order */
> + FSMRelation *nextPhysical; /* next rel in arena-storage order */
> + FSMRelation *priorPhysical; /* prior rel in arena-storage order */
> + bool isIndex; /* if true, we store only page numbers */
> + Size avgRequest; /* moving average of space requests */
> + int lastPageCount; /* pages passed to RecordRelationFreeSpace */
> + int firstChunk; /* chunk # of my first chunk in arena */
> + int storedPages; /* # of pages stored in arena */
> + int nextPage; /* index (from 0) to start next search at */
> + };
> +
> +
> +
> /* GUC variables */
> extern int MaxFSMRelations;
> extern int MaxFSMPages;
> ***************
> *** 62,67 ****
> --- 158,164 ----
>
> extern void DumpFreeSpaceMap(int code, Datum arg);
> extern void LoadFreeSpaceMap(void);
> + extern FSMHeader *GetFreeSpaceMap(void);
>
> #ifdef FREESPACE_DEBUG
> extern void DumpFreeSpace(void);
>
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 12:00 AM
Mark Kirkwood
 
Posts: n/a
Default Re: TODO Item - Add system view to show free space map

Christopher Kings-Lynne wrote:
> Want to host it on pgfoundry until 8.2 is released?
>


Absolutely - I'll let it run the gauntlet of freedback to fix the silly
mistakes I put in :-), then do patches for 8.1 and 8.0 (maybe 7.4 and
7.3 as well - if it rains a lot....).

cheers

Mark


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:34 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727