2006-02-12 11:55:53 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pg_freespacemap.c
|
2008-09-30 19:17:07 +08:00
|
|
|
* display contents of a free space map
|
2006-02-12 11:55:53 +08:00
|
|
|
*
|
2008-09-30 19:17:07 +08:00
|
|
|
* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.11 2008/09/30 11:17:07 heikki Exp $
|
2006-02-12 11:55:53 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
2006-05-05 04:39:34 +08:00
|
|
|
|
2008-09-30 19:17:07 +08:00
|
|
|
#include "access/heapam.h"
|
2008-05-12 08:00:54 +08:00
|
|
|
#include "access/htup.h"
|
2006-02-12 11:55:53 +08:00
|
|
|
#include "catalog/pg_type.h"
|
2008-05-12 08:00:54 +08:00
|
|
|
#include "funcapi.h"
|
2006-02-12 11:55:53 +08:00
|
|
|
#include "storage/freespace.h"
|
2008-09-30 19:17:07 +08:00
|
|
|
#include "utils/builtins.h"
|
2006-05-05 04:39:34 +08:00
|
|
|
|
2006-02-12 11:55:53 +08:00
|
|
|
|
2006-05-31 06:12:16 +08:00
|
|
|
PG_MODULE_MAGIC;
|
|
|
|
|
2008-09-30 19:17:07 +08:00
|
|
|
Datum pg_freespace(PG_FUNCTION_ARGS);
|
|
|
|
Datum pg_freespacedump(PG_FUNCTION_ARGS);
|
2006-04-27 06:46:09 +08:00
|
|
|
|
|
|
|
/*
|
2008-09-30 19:17:07 +08:00
|
|
|
* Returns the amount of free space on a given page, according to the
|
|
|
|
* free space map.
|
2006-04-27 06:46:09 +08:00
|
|
|
*/
|
2008-09-30 19:17:07 +08:00
|
|
|
PG_FUNCTION_INFO_V1(pg_freespace);
|
2006-05-05 04:39:34 +08:00
|
|
|
|
2006-04-27 06:46:09 +08:00
|
|
|
Datum
|
2008-09-30 19:17:07 +08:00
|
|
|
pg_freespace(PG_FUNCTION_ARGS)
|
2006-04-27 06:46:09 +08:00
|
|
|
{
|
2008-09-30 19:17:07 +08:00
|
|
|
Oid relid = PG_GETARG_OID(0);
|
|
|
|
uint32 blkno = PG_GETARG_UINT32(1);
|
|
|
|
int16 freespace;
|
|
|
|
Relation rel;
|
2006-05-05 04:39:34 +08:00
|
|
|
|
2008-09-30 19:17:07 +08:00
|
|
|
rel = relation_open(relid, AccessShareLock);
|
2006-10-04 08:30:14 +08:00
|
|
|
|
2008-09-30 19:17:07 +08:00
|
|
|
if (!BlockNumberIsValid(blkno))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
|
|
errmsg("invalid block number")));
|
2006-04-27 06:46:09 +08:00
|
|
|
|
2008-09-30 19:17:07 +08:00
|
|
|
freespace = GetRecordedFreeSpace(rel, blkno);
|
2006-04-27 06:46:09 +08:00
|
|
|
|
2008-09-30 19:17:07 +08:00
|
|
|
relation_close(rel, AccessShareLock);
|
|
|
|
PG_RETURN_INT16(freespace);
|
2006-04-27 06:46:09 +08:00
|
|
|
}
|