OSDN Git Service

Avoid using trivial usernames in foreign_data regression test.
[pg-rex/syncrep.git] / contrib / pg_freespacemap / pg_freespacemap.c
1 /*-------------------------------------------------------------------------
2  *
3  * pg_freespacemap.c
4  *        display contents of a free space map
5  *
6  *        $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.14 2009/06/11 14:48:51 momjian Exp $
7  *-------------------------------------------------------------------------
8  */
9 #include "postgres.h"
10
11 #include "access/heapam.h"
12 #include "funcapi.h"
13 #include "storage/block.h"
14 #include "storage/freespace.h"
15
16
17 PG_MODULE_MAGIC;
18
19 Datum           pg_freespace(PG_FUNCTION_ARGS);
20
21 /*
22  * Returns the amount of free space on a given page, according to the
23  * free space map.
24  */
25 PG_FUNCTION_INFO_V1(pg_freespace);
26
27 Datum
28 pg_freespace(PG_FUNCTION_ARGS)
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 (blkno < 0 || blkno > MaxBlockNumber)
38                 ereport(ERROR,
39                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
40                                  errmsg("invalid block number")));
41
42         freespace = GetRecordedFreeSpace(rel, blkno);
43
44         relation_close(rel, AccessShareLock);
45         PG_RETURN_INT16(freespace);
46 }