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

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (pg_freespace)
 
Datum pg_freespace (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ pg_freespace()

Datum pg_freespace ( PG_FUNCTION_ARGS  )

Definition at line 24 of file pg_freespacemap.c.

25 {
26  Oid relid = PG_GETARG_OID(0);
27  int64 blkno = PG_GETARG_INT64(1);
28  int16 freespace;
29  Relation rel;
30 
31  rel = relation_open(relid, AccessShareLock);
32 
33  if (blkno < 0 || blkno > MaxBlockNumber)
34  ereport(ERROR,
35  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
36  errmsg("invalid block number")));
37 
38  freespace = GetRecordedFreeSpace(rel, blkno);
39 
41  PG_RETURN_INT16(freespace);
42 }
#define MaxBlockNumber
Definition: block.h:35
signed short int16
Definition: c.h:496
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_RETURN_INT16(x)
Definition: fmgr.h:356
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
Definition: freespace.c:244
#define AccessShareLock
Definition: lockdefs.h:36
unsigned int Oid
Definition: postgres_ext.h:31
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47

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

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( pg_freespace  )

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 15 of file pg_freespacemap.c.