mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	as determined by IWYU
Similar to commit dbbca2cf29, but for contrib, pl, and src/test/.
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/0df1d5b1-8ca8-4f84-93be-121081bde049%40eisentraut.org
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			978 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			978 B
		
	
	
	
		
			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;
 | |
| 
 | |
| /*
 | |
|  * 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);
 | |
| }
 |