Segment-Page Storage Functions
-
local_segment_space_info(tablespacename TEXT, databasename TEXT)
Description: Generates usage information about all extent groups in the tablespace.
Return type:
Example:
select * from local_segment_space_info('pg_default', 'postgres'); node_name | extent_size | forknum | total_blocks | meta_data_blocks | used_data_blocks | utilization | high_water_mark -------------------+-------------+---------+--------------+------------------+------------------+-------------+----------------- dn_6001_6002_6003 | 1 | 0 | 16384 | 4157 | 1 | .253784 | 4158 dn_6001_6002_6003 | 8 | 0 | 16384 | 4157 | 8 | .254211 | 4165 (2 rows) -
pg_stat_segment_extent_usage(int4 tablespace oid, int4 database oid, int4 extent_type, int4 forknum)
Description: Specifies the usage information of each allocated extent in an extent group returned each time. extent_type indicates the type of the extent group. The value is an integer ranging from 1 to 5. If the value is not within the range, an error is reported. forknum indicates the fork number. The value is an integer ranging from 0 to 4. Currently, only the following values are valid: 0 for data files, 1 for FSM files, and 2 for visibility map files.
Return type:
The value of usage_type is enumerated. The meaning of each value is as follows:
- Non-bucket table segment head: data segment head of a non-hash bucket table
- Non-bucket table fork head: fork segment header of a non-segment-page table
- Data extent: data block
Example:
select * from pg_stat_segment_extent_usage((select oid::int4 from pg_tablespace where spcname='pg_default'), (select oid::int4 from pg_database where datname='postgres'), 1, 0); start_block | extent_size | usage_type | ower_location | special_data -------------+-------------+------------------------+---------------+-------------- 4157 | 1 | Data extent | 4294967295 | 0 4158 | 1 | Data extent | 4157 | 0 -
local_space_shrink(tablespacename TEXT, databasename TEXT)
Description: Shrinks specified physical segment-page space on the current node. Only the currently connected database can be shrank.
Return value: empty
-
gs_space_shrink(int4 tablespace, int4 database, int4 extent_type, int4 forknum)
Description: Works similar to local_space_shrink, that is, shrinks specified physical segment-page space. However, the parameters are different. The input parameters are the OIDs of the tablespace and database, and the value of extent_type is an integer ranging from 2 to 5. Note: The value 1 of extent_type indicates segment-page metadata. Currently, the physical file that contains the metadata cannot be shrunk. This function is used only by tools. You are not advised to use it directly.
Return value: empty
-
pg_stat_remain_segment_info()
Description: Displays residual extents on the current node due to faults. Residual extents are classified into two types: segments that are allocated but not used and extents that are allocated but not used. The main difference is that a segment contains multiple extents. During reclamation, all extents in the segment need to be recycled.
Return type:
Extent type. The options are as follows: ALLOC_SEGMENT, DROP_SEGMENT, and SHRINK_EXTENT.
The values of type are described as follows:
-
ALLOC_SEGMENT: When a user creates a segment-page table and the segment is just allocated but the transaction of creating a table is not committed, the node is faulty. As a result, the segment is not used after being allocated.
-
DROP_SEGMENT: When a user deletes a segment-page table and the transaction is successfully committed, the bit corresponding to the segment page of the table is not reset and a fault, such as power failure, occurs. As a result, the segment is not used or released.
-
SHRINK_EXTENT: When a user shrinks a segment-page table and does not release the idle extent, a fault, such as power failure, occurs. As a result, the extent remains and cannot be reused.
Example:
select * from pg_stat_remain_segment_info(); space_id | db_id | block_id | type ----------+-------+----------+------ 1663 | 16385| 4156| ALLOC_SEGMENT
-
-
pg_free_remain_segment(int4 spaceId, int4 dbId, int4 segmentId)
Description: Releases a specified residual extent. The value must be obtained from the pg_stat_remain_segment_info function. The function verifies input values. If the specified extent is not among the recorded residual extents, an error message is returned. If the specified extent is a single extent, the extent is released independently. If it is a segment, the segment and all extents in the segment are released.
Return value: empty
-
gs_table_shrink(tablename TEXT, tablespacename TEXT, databasename TEXT)
Description: Performs space reclamation on a specified segment-page table. The function reclaims free extents at the tail of the table and returns them to the file for reuse by other objects. It also attempts to compact the table by relocating valid data from the tail into earlier free space. Currently, only segment-page tables in the currently connected database are supported. Unsupported scenarios will be detected and result in an error.
Return value: Returns the number of extents reclaimed during this shrink operation
NOTICE:
During the execution of this function, data may be relocated, causing indexes to become invalid and require rebuilding. Please use with caution. -
gs_space_shrink_compact(tablespacename TEXT, databasename TEXT)
Description: Performs physical space reclamation and compaction for the specified segment-page tablespace. The function attempts to reorganize extents within the tablespace into a compact layout and updates the high water mark to free unused space at the tail. The physical file size is aligned to 128 MB. Currently, only segment-page tablespaces in the currently connected database are supported. Unsupported scenarios will be checked before execution and an error will be returned.
Return value: empty