Updated on 2026-01-06 GMT+08:00

Memory Management Functions

This function is supported only by cluster versions 9.1.0 and later.

pg_shared_chunk_detail(contextname char(64))

Description: Queries information about all chunks requested by the memory context in a specified shared memory.

The contextname parameter indicates the name of the memory context.

Before using this function, use the pg_shared_chunk_dump(contextname char(64)) function to print related information to a file.

Return type: record

Example:

1
2
3
4
5
6
7
8
SELECT * FROM pg_shared_chunk_detail('pgstat file hash table');
       parent        | level |  file_name   | line_number | chunk_size | requested_number | total_size 
---------------------+-------+--------------+-------------+------------+------------------+------------
 pgstat file context |     2 | dynahash.cpp |         158 |       2048 |                1 |       2048
 pgstat file context |     2 | dynahash.cpp |         158 |        256 |                1 |        256
 pgstat file context |     2 | dynahash.cpp |         158 |       4096 |                9 |      36864
 pgstat file context |     2 | dynahash.cpp |         158 |       8192 |                4 |      32768
(4 rows)

pv_session_chunk_detail(tid int, contextname char(64))

Description: Queries information about all chunks applied for by a memory context created by a specified thread.

The tid parameter indicates the thread ID, while the contextname parameter indicates the memory context name.

To use this function, you need to use the pv_session_chunk_dump(tid int, contextname char(64)) function to print related information to a file.

Return type: record

Example:

1
2
3
4
5
6
7
8
9
SELECT * FROM pv_session_chunk_detail(140178810990936, 'Timezones');
      parent      | level |   file_name   | line_number | chunk_size | requested_number | total_size 
------------------+-------+---------------+-------------+------------+------------------+------------
 TopMemoryContext |     1 | dynahash.cpp  |         158 |       1280 |                2 |       2560
 TopMemoryContext |     1 | dynahash.cpp  |         158 |        160 |                1 |        160
 TopMemoryContext |     1 | dynahash.cpp  |         158 |       2560 |                2 |       5120
 TopMemoryContext |     1 | localtime.cpp |        1965 |        128 |                1 |        128
 TopMemoryContext |     1 | localtime.cpp |        1965 |        448 |                1 |        448
(5 rows)

pg_shared_chunk_dump(contextname char(64))

Description: Prints information about all chunks applied for by the memory context in the specified shared memory as a file.

The contextname parameter indicates the name of the memory context.

Return type: Boolean

Example:

1
2
3
4
5
SELECT * FROM pg_shared_chunk_dump('pgstat file hash table');
 pg_shared_chunk_dump 
----------------------
         t
(1 row)

pv_session_chunk_dump(tid int, contextname char(64))

Description: Prints information about all chunks applied for by a memory context created by a specified thread into a file.

The tid parameter indicates the thread ID, while the contextname parameter indicates the memory context name.

Return type: Boolean

Example:

1
2
3
4
5
SELECT * FROM pv_session_chunk_dump(140472797325280, 'Timezones');
 pv_session_chunk_dump 
-----------------------
 t
(1 row)

gs_print_memory_profiling()

Description: Prints memory collection details. This function is available only for clusters of version 9.1.1.100 or later.

Return type: Boolean

Example:

1
2
3
4
5
SELECT * FROM gs_print_memory_profiling();
 gs_print_memory_profiling 
----------------------------
 t
(1 row)

gs_gsc_dbstat_info(database_id bigint DEFAULT NULL::bigint)

Description: Queries the statistics of Global SysCache on the current node, such as the SysCache cache hit information and LRU-based eviction. This function is available only for clusters of version 9.1.1.100 or later.

The parameter database_id indicate the database OID.

  • When database_id is left blank, statistics about all databases are queried.
  • When database_id is 0, the statistics of the shared database are queried.
  • When database_id is a valid database OID, the statistics of the shared database and the database are queried.

Return type: record

Return columns:

Column

Type

Description

database_id

BIGINT

Database OID

database_name

TEXT

Database name

tup_searches

BIGINT

Number of system catalog cache searches

tup_hits

BIGINT

Number of system catalog cache hits

tup_miss

BIGINT

Number of table scans triggered by system catalog cache misses.

tup_swapout_count

BIGINT

Number of tuples evicted by LRU

tup_count

BIGINT

Number of tuples in the cache

tup_dead

BIGINT

Number of tuples in the garbage queue

tup_memory

BIGINT

Total memory of tuples in the cache

total_memory

BIGINT

Total memory of the Global SysCache

refcount

BIGINT

Number of times that Global SysCache is referenced by threads.

Example:

1
2
3
4
5
6
SELECT * FROM gs_gsc_dbstat_info();
 database_id | database_name | tup_searches | tup_hits | tup_miss | tup_swapout_count | tup_count | tup_dead | tup_memory | total_memory | refcount
-------------+---------------+--------------+----------+----------+-------------------+-----------+----------+------------+--------------+----------
           0 |               |        12474 |     9876 |       14 |                 0 |        16 |        0 |      12560 |       697664 |        0
       17185 | postgres      |        10156 |     5521 |     2223 |                 0 |      1398 |        0 |     752296 |      4417856 |       11
(2 rows)

gs_gsc_clean(database_id bigint DEFAULT NULL::bigint)

Description: Clears the Global SysCache of a specified database. This function is available only for clusters of version 9.1.1.100 or later.

The parameter database_id indicate the database OID.

  • When database_id is left blank, the memory of all databases is cleared.
  • When database_id is 0, the memory of the shared databases is cleared.
  • When database_id is a valid database OID, the memory of both the shared databases and the specified database is cleared.

Return type: bool

Example:

1
2
3
4
5
SELECT * FROM gs_gsc_clean();
 gs_gsc_clean
--------------
 t
(1 row)

gs_table_oscache(regclass)

Description: Queries the cache status of table data files in the OS file cache. This function is supported only by clusters of version 9.1.1.200 or later.

This function involves mmap locks and is not recommended to be used frequently.

Return type: record

The following table describes return columns.

Column

Type

Description

schema_name

TEXT

Schema name.

table_name

TEXT

Table name.

file_name

TEXT

Data file name.

file_type

TEXT

File type.

seg_count

INTEGER

File segment number.

file_size

BIGINT

File size.

cache_size

BIGINT

Size of the file that is cached.

con_cache_count

BIGINT

Number of consecutive cached pages.

cache_dirty_size

BIGINT

Size of dirty pages in the cache.

con_cache_dirty_count

BIGINT

Number of consecutive cached pages.

in_fd_cache

BOOLEAN

Whether the file is in the fd cache, that is, whether the file is open.

Example:

1
2
3
4
5
SELECT * FROM gs_table_oscache('employee');
 schema_name | table_name |    file_name     | file_type | seg_count | file_size | cache_size | con_cache_count | cache_dirty_size | con_cache_dirty_count | in_fd_cache
-------------+------------+------------------+-----------+-----------+-----------+------------+-----------------+------------------+-----------------------+-------------
 public      | employee   | base/17253/17103 | RowRel    |         1 |         0 |          0 |               0 |                0 |                     0 | f
(1 row)

gs_table_freecache(regclass)

Description: Clears the OS file cache of the data files of a specified table. This function cannot clear the data files that are still open. This function is supported only by clusters of version 9.1.1.200 or later.

Return type: bool

Example:

1
2
3
4
5
SELECT * FROM gs_table_freecache('employee');
 gs_table_freecache
--------------------
 t
(1 row)

gs_file_freecache(IN file_path TEXT)

Description: Clears the OS file cache of a specified file. This function can clear files that are still open. This function is supported only by clusters of version 9.1.1.200 or later.

file_path: indicates the file path.

Return type: bool

Example:

1
2
3
4
5
SELECT * FROM gs_file_freecache('base/17253/17103');
 gs_file_freecache
-------------------
 t
(1 row)