PostgreSQL Source Code  git master
pg_freespacemap.c File Reference
#include "postgres.h"
#include "funcapi.h"
#include "storage/freespace.h"
Include dependency graph for pg_freespacemap.c:

Go to the source code of this file.


 PG_FUNCTION_INFO_V1 (pg_freespace)
Datum pg_freespace (PG_FUNCTION_ARGS)



Function Documentation

◆ pg_freespace()

Datum pg_freespace ( PG_FUNCTION_ARGS  )

Definition at line 23 of file pg_freespacemap.c.

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, GetRecordedFreeSpace(), MaxBlockNumber, PG_GETARG_INT64, PG_GETARG_OID, PG_RETURN_INT16, relation_close(), and relation_open().

24 {
25  Oid relid = PG_GETARG_OID(0);
26  int64 blkno = PG_GETARG_INT64(1);
27  int16 freespace;
28  Relation rel;
30  rel = relation_open(relid, AccessShareLock);
32  if (blkno < 0 || blkno > MaxBlockNumber)
33  ereport(ERROR,
35  errmsg("invalid block number")));
37  freespace = GetRecordedFreeSpace(rel, blkno);
40  PG_RETURN_INT16(freespace);
41 }
signed short int16
Definition: c.h:312
#define AccessShareLock
Definition: lockdefs.h:36
#define PG_RETURN_INT16(x)
Definition: fmgr.h:321
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1270
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define MaxBlockNumber
Definition: block.h:35
#define PG_GETARG_OID(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
Definition: freespace.c:230
int errmsg(const char *fmt,...)
Definition: elog.c:797
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1124
#define PG_GETARG_INT64(n)
Definition: fmgr.h:252


PG_FUNCTION_INFO_V1 ( pg_freespace  )

Variable Documentation



Definition at line 14 of file pg_freespacemap.c.