1 /*-------------------------------------------------------------------------
4 * display contents of a free space map
6 * contrib/pg_freespacemap/pg_freespacemap.c
7 *-------------------------------------------------------------------------
11 #include "access/relation.h"
13 #include "storage/freespace.h"
18 * Returns the amount of free space on a given page, according to the
21 PG_FUNCTION_INFO_V1(pg_freespace);
24 pg_freespace(PG_FUNCTION_ARGS)
26 Oid relid = PG_GETARG_OID(0);
27 int64 blkno = PG_GETARG_INT64(1);
31 rel = relation_open(relid, AccessShareLock);
33 if (blkno < 0 || blkno > MaxBlockNumber)
35 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
36 errmsg("invalid block number")));
38 freespace = GetRecordedFreeSpace(rel, blkno);
40 relation_close(rel, AccessShareLock);
41 PG_RETURN_INT16(freespace);