PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_freespacemap.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_freespacemap.c
4  * display contents of a free space map
5  *
6  * contrib/pg_freespacemap/pg_freespacemap.c
7  *-------------------------------------------------------------------------
8  */
9 #include "postgres.h"
10 
11 #include "funcapi.h"
12 #include "storage/freespace.h"
13 
15 
16 /*
17  * Returns the amount of free space on a given page, according to the
18  * free space map.
19  */
21 
22 Datum
24 {
25  Oid relid = PG_GETARG_OID(0);
26  int64 blkno = PG_GETARG_INT64(1);
27  int16 freespace;
28  Relation rel;
29 
30  rel = relation_open(relid, AccessShareLock);
31 
32  if (blkno < 0 || blkno > MaxBlockNumber)
33  ereport(ERROR,
34  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
35  errmsg("invalid block number")));
36 
37  freespace = GetRecordedFreeSpace(rel, blkno);
38 
40  PG_RETURN_INT16(freespace);
41 }
signed short int16
Definition: c.h:252
#define AccessShareLock
Definition: lockdefs.h:36
#define PG_RETURN_INT16(x)
Definition: fmgr.h:300
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1263
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:231
Datum pg_freespace(PG_FUNCTION_ARGS)
#define ereport(elevel, rest)
Definition: elog.h:122
Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk)
Definition: freespace.c:270
uintptr_t Datum
Definition: postgres.h:374
PG_MODULE_MAGIC
PG_FUNCTION_INFO_V1(pg_freespace)
int errmsg(const char *fmt,...)
Definition: elog.c:797
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1117
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
#define PG_GETARG_INT64(n)
Definition: fmgr.h:238