mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
It seems potentially useful to label our shared libraries with version information, now that a facility exists for retrieving that. This patch labels them with the PG_VERSION string. There was some discussion about using semantic versioning conventions, but that doesn't seem terribly helpful for modules with no SQL-level presence; and for those that do have SQL objects, we typically expect them to support multiple revisions of the SQL definitions, so it'd still not be very helpful. I did not label any of src/test/modules/. It seems unnecessary since we don't install those, and besides there ought to be someplace that still provides test coverage for the original PG_MODULE_MAGIC macro. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/dd4d1b59-d0fe-49d5-b28f-1e463b68fa32@gmail.com
46 lines
1.0 KiB
C
46 lines
1.0 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* pg_freespacemap.c
|
|
* display contents of a free space map
|
|
*
|
|
* contrib/pg_freespacemap/pg_freespacemap.c
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#include "postgres.h"
|
|
|
|
#include "access/relation.h"
|
|
#include "fmgr.h"
|
|
#include "storage/freespace.h"
|
|
|
|
PG_MODULE_MAGIC_EXT(
|
|
.name = "pg_freespacemap",
|
|
.version = PG_VERSION
|
|
);
|
|
|
|
/*
|
|
* Returns the amount of free space on a given page, according to the
|
|
* free space map.
|
|
*/
|
|
PG_FUNCTION_INFO_V1(pg_freespace);
|
|
|
|
Datum
|
|
pg_freespace(PG_FUNCTION_ARGS)
|
|
{
|
|
Oid relid = PG_GETARG_OID(0);
|
|
int64 blkno = PG_GETARG_INT64(1);
|
|
int16 freespace;
|
|
Relation rel;
|
|
|
|
rel = relation_open(relid, AccessShareLock);
|
|
|
|
if (blkno < 0 || blkno > MaxBlockNumber)
|
|
ereport(ERROR,
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
errmsg("invalid block number")));
|
|
|
|
freespace = GetRecordedFreeSpace(rel, blkno);
|
|
|
|
relation_close(rel, AccessShareLock);
|
|
PG_RETURN_INT16(freespace);
|
|
}
|