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

Go to the source code of this file.

Functions

 PG_MODULE_MAGIC_EXT (.name="pg_freespacemap",.version=PG_VERSION)
 
 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 28 of file pg_freespacemap.c.

29{
30 Oid relid = PG_GETARG_OID(0);
31 int64 blkno = PG_GETARG_INT64(1);
32 int16 freespace;
33 Relation rel;
34
35 rel = relation_open(relid, AccessShareLock);
36
37 if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
39 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
40 errmsg("relation \"%s\" does not have storage",
43
44 if (blkno < 0 || blkno > MaxBlockNumber)
46 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
47 errmsg("invalid block number")));
48
49 freespace = GetRecordedFreeSpace(rel, blkno);
50
52 PG_RETURN_INT16(freespace);
53}
#define MaxBlockNumber
Definition: block.h:35
int64_t int64
Definition: c.h:499
int16_t int16
Definition: c.h:497
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#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
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
unsigned int Oid
Definition: postgres_ext.h:30
#define RelationGetRelationName(relation)
Definition: rel.h:550
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
Form_pg_class rd_rel
Definition: rel.h:111

References AccessShareLock, ereport, errcode(), errdetail_relkind_not_supported(), errmsg(), ERROR, GetRecordedFreeSpace(), MaxBlockNumber, PG_GETARG_INT64, PG_GETARG_OID, PG_RETURN_INT16, RelationData::rd_rel, relation_close(), relation_open(), and RelationGetRelationName.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( pg_freespace  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "pg_freespacemap",
version = PG_VERSION 
)