postgresql/contrib/pg_freespacemap/pg_freespacemap.c
Andres Freund 111944c5ee Replace heapam.h includes with {table, relation}.h where applicable.
A lot of files only included heapam.h for relation_open, heap_open etc
- replace the heapam.h include in those files with the narrower
header.

Author: Andres Freund
Discussion: https://postgr.es/m/20190111000539.xbv7s6w7ilcvm7dp@alap3.anarazel.de
2019-01-21 10:51:37 -08:00

43 lines
981 B
C

/*-------------------------------------------------------------------------
*
* pg_freespacemap.c
* display contents of a free space map
*
* contrib/pg_freespacemap/pg_freespacemap.c
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/relation.h"
#include "funcapi.h"
#include "storage/freespace.h"
PG_MODULE_MAGIC;
/*
* Returns the amount of free space on a given page, according to the
* free space map.
*/
PG_FUNCTION_INFO_V1(pg_freespace);
Datum
pg_freespace(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 blkno = PG_GETARG_INT64(1);
int16 freespace;
Relation rel;
rel = relation_open(relid, AccessShareLock);
if (blkno < 0 || blkno > MaxBlockNumber)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid block number")));
freespace = GetRecordedFreeSpace(rel, blkno);
relation_close(rel, AccessShareLock);
PG_RETURN_INT16(freespace);
}