1 /*-------------------------------------------------------------------------
4 * display contents of a free space map
7 *-------------------------------------------------------------------------
11 #include "access/heapam.h"
13 #include "storage/block.h"
14 #include "storage/freespace.h"
19 Datum
pg_freespace(PG_FUNCTION_ARGS
);
22 * Returns the amount of free space on a given page, according to the
25 PG_FUNCTION_INFO_V1(pg_freespace
);
28 pg_freespace(PG_FUNCTION_ARGS
)
30 Oid relid
= PG_GETARG_OID(0);
31 int64 blkno
= PG_GETARG_INT64(1);
35 rel
= relation_open(relid
, AccessShareLock
);
37 if (blkno
< 0 || blkno
> MaxBlockNumber
)
39 (errcode(ERRCODE_INVALID_PARAMETER_VALUE
),
40 errmsg("invalid block number")));
42 freespace
= GetRecordedFreeSpace(rel
, blkno
);
44 relation_close(rel
, AccessShareLock
);
45 PG_RETURN_INT16(freespace
);