Statistics Functions
pg_stat_get_activity(integer)
Description: Returns a record of a background process with a specific PID. When the parameter is NULL, it returns records of all active background processes. The result is a subset of the PG_STAT_ACTIVITY view, excluding the connection_info column.
Return type: SETOF record.
gs_stack()
Description: Obtains the stack information of a CN or DN process. The input parameters actor_name and tid need to be obtained through views or other functions. lwtid is not supported. gs_stack() provides a more flexible and faster method for obtaining stacks than the gdb and gstack commands. It is recommended that administrators use this tool only during fault analysis and locating. It is not recommended that this tool be used as a routine monitoring tool.
- actor_name: name of the actor where the thread is located.
- tid: thread ID.
- lwtid: lightweight thread ID.
- stack: stack information about the tid or lwtid thread.
The gs_stack() function can be used in the following ways:
- Method 1: If the input parameter of the gs_stack() function is empty, the stacks of all threads on the CNs and DNs are printed.
Obtaining the running stacks of all threads on CNs and all DNs takes a long time, which affects normal service running. Therefore, you are advised not to use this function frequently.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
select * from gs_stack(); actor_name | tid | lwtid | stack --------------+-----------------+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------- coordinator1 | 106927505866816 | 186762 | GsStackBacktrace(int) + 0x1a + | | | 0x7ffb45f6d1f0 + | | | __poll + 0x4f + | | | poll + 0xa0 + | | | poll(pollfd*, unsigned long, int, void (*)()) + 0x19e + | | | ServerLoop() + 0x570 + | | | PmStartupThreads() + 0x167 + | | | PostmasterMain(int, char**) + 0x22f | | | coordinator1 | 106927505998400 | 186773 | GsStackBacktrace(int) + 0x1a + | | | 0x7ffb45f6d1f0 + | | | 0x7ffb45fb41aa + | | | pthread_cond_clockwait + 0x1e2 + | | | std::__condvar::wait_until(std::mutex&, int, timespec&) + 0x39
- Method 2: Set the input parameter of the gs_stack(actor_name) function to the specified actor_name, indicating that the stacks of all threads on the actor named actor_name are printed.
- actor_name must be the name of a CN or DN. Otherwise, the error message "invalid actor_name" is displayed.
- The value of actor_name can be obtained from other views or functions (for example, the pgxc_query_wait_status function).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
select * from gs_stack('coordinator1'); actor_name | tid | lwtid | stack --------------+-----------------+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------- coordinator1 | 106927505866816 | 186762 | GsStackBacktrace(int) + 0x1a + | | | 0x7ffb45f6d1f0 + | | | __poll + 0x4f + | | | poll + 0xa0 + | | | poll(pollfd*, unsigned long, int, void (*)()) + 0x19e + | | | ServerLoop() + 0x570 + | | | PmStartupThreads() + 0x167 + | | | PostmasterMain(int, char**) + 0x22f
- Method 3: The input parameters of the gs_stack(actor_name, tid) function are actor_name and tid, indicating that the stack of the specified tid thread on the actor named actor_name is printed.
- actor_name must be the name of a CN or DN. Otherwise, the error message "invalid actorName" is displayed.
- The values of actor_name and tid need to be obtained from other views or functions (for example, the pgxc_query_wait_status function).
- Obtains the running stack of a specified thread in a specified CN or DN process. This method is recommended because it takes a short time and does not affect service running.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
select * from gs_stack('coordinator1',106927505998400); actor_name | tid | lwtid | stack --------------+-----------------+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------- coordinator1 | 106927505998400 | 186773 | GsStackBacktrace(int) + 0x1a + | | | 0x7ffb45f6d1f0 + | | | 0x7ffb45fb41aa + | | | pthread_cond_clockwait + 0x1e2 + | | | std::__condvar::wait_until(std::mutex&, int, timespec&) + 0x39 + | | (1 row)
gs_wlm_session_statistics()
Description: Retrieves monitoring information for SQL statements currently being executed. It does not capture monitoring information for completed SQL statements. Each row in the returned results indicates one statement.
Fields returned by the function:
| Column | Type | Description |
|---|---|---|
| session_id | text | Session ID of a statement. |
| statement_id | text | Statement ID. |
| start_time | timestamp with time zone | Start time of a statement. |
| duration | bigint | Statement running duration. Unit: ms. |
| estimate_total_time | bigint | Estimated statement running duration. Unit: ms. |
| estimate_left_time | bigint | Estimated remaining running duration of a statement. Unit: ms. |
| cn_actor_info | text | Serverless information of a CN. |
| dn_actor_info | text | Serverless information of a DN. |
| startup_coordinator_duration | bigint | Duration to start a CN. Unit: ms. |
| create_session_duration | bigint | Duration to create a session. Unit: ms. |
| enqueue_statement_duration | bigint | Duration to add a statement to a task queue. Unit: ms. |
| queue_duration | bigint | Queuing duration of a statement in a task queue. Unit: ms. |
| write_resultset_duration | bigint | Duration to write a statement to a result set. Unit: ms. |
| queryid | bigint | ID of a debug query. |
| schemaname | text | Schema name when a statement is executed. |
| query | text | Statement. |
| query_plan | text | Explain information. |
| tid | bigint | Thread ID. |
| parse_time | bigint | Time from parsing to execution start. Unit: ms. |
| estimate_memory | int | Estimated memory of a statement. Unit: MB. |
| min_dn_time | bigint | Minimum DN duration. Unit: ms. |
| max_dn_time | bigint | Maximum DN duration. Unit: ms. |
| average_dn_time | bigint | Average DN duration. Unit: ms. |
| dn_time_skew_percent | int | Skew percentage of DN duration. Unit: %. |
| dn_min_cpu_time | bigint | Minimum DN CPU duration. Unit: ms. |
| dn_max_cpu_time | bigint | Maximum DN CPU duration. Unit: ms. |
| dn_average_cpu_time | bigint | Average DN CPU duration. Unit: ms. |
| dn_total_cpu_time | bigint | Total DN CPU duration. Unit: ms. |
| dn_cpu_skew_percent | int | Skew percentage of DN CPU duration. Unit: %. |
| dn_min_peak_memory | int | Minimum peak memory of all DNs. Unit: MB. |
| dn_max_peak_memory | int | Maximum peak memory of all DNs. Unit: MB. |
| dn_average_peak_memory | int | Average peak memory of all DNs. Unit: MB. |
| dn_memory_skew_percent | int | Memory skew rate. Unit: %. |
| dn_spill_num | int | Number of DNs with disk spills. |
| dn_spill_count | int | Number of DNs with disk spills. |
| dn_min_spill_size | bigint | Minimum spill size. Unit: MB. |
| dn_max_spill_size | bigint | Maximum spill size. Unit: MB. |
| dn_average_spill_size | bigint | Average spill size. Unit: MB. |
| dn_spill_skew_percent | int | Spill skew rate. Unit: %. |
| dn_write_disk_total_size | bigint | Total size of data written to disks on a DN. Unit: MB. |
| dn_write_disk_max_size | bigint | Maximum amount of data written to disks on a DN. Unit: MB. |
| dn_write_disk_min_size | bigint | Minimum amount of data written to disks on a DN. Unit: MB. |
| dn_spill_obs_total_size | bigint | Total amount of data spilled to OBS by a DN. Unit: MB. |
| dn_spill_obs_max_size | bigint | Maximum amount of data spilled to OBS by a DN. Unit: MB. |
| dn_spill_obs_min_size | bigint | Minimum amount of data spilled to OBS by a DN. Unit: MB. |
| dn_write_obs_total_size | bigint | Total amount of data directly written to OBS by a DN. Unit: MB. |
| dn_write_obs_max_size | bigint | Maximum amount of data directly written to OBS by a DN. Unit: MB. |
| dn_write_obs_min_size | bigint | Minimum amount of data directly written to OBS by a DN. Unit: MB. |
| cn_spill_count | int | Number of spills from a CN. |
| cn_spill_size | bigint | Total size of data spilled from a CN. Unit: MB. |
| cn_spill_obs_size | bigint | Amount of data spilled to OBS by a CN. Unit: MB. |
| cn_write_obs_size | bigint | Amount of data directly written to OBS by a CN. Unit: MB. |
| cn_write_obs_disk_size | bigint | Amount of data spilled to local disks by a CN. Unit: MB. |
| disk_cache_hit_ratio | numeric | Disk cache hit rate. |
| disk_cache_disk_read_size | bigint | Read size of disk cache. Unit: byte. |
| disk_cache_disk_write_size | bigint | Write size of disk cache. Unit: byte. |
| disk_cache_remote_read_size | bigint | Remote read size of disk cache. Unit: byte. |
| disk_cache_remote_read_time | bigint | Count of remote reads from disk cache. Unit: times. |
| vfs_scan_bytes | bigint | Bytes scanned by the OBS file system. Unit: byte. |
| vfs_remote_read_bytes | bigint | Bytes remotely read by the OBS file system. Unit: byte. |
| disk_cache_load_time | bigint | Local load time of disk cache. Unit: μs. |
| disk_cache_conflict_count | bigint | Hash collision count of disk cache blocks. Unit: times. |
| disk_cache_error_count | bigint | Error count of disk cache. Unit: times. |
| disk_cache_error_code | bigint | Error code of disk cache. |
| obs_io_req_avg_rtt | bigint | Average round-trip time of OBS I/O requests. Unit: μs. |
| obs_io_req_avg_latency | bigint | Average latency of OBS I/O requests. Unit: μs. |
| obs_io_req_latency_gt_1s | bigint | Count of OBS I/O request delays exceeding 1s. Unit: times. |
| obs_io_req_latency_gt_10s | bigint | Count of OBS I/O request delays exceeding 10s. Unit: times. |
| obs_io_req_count | bigint | Number of OBS I/O requests. Unit: times. |
| obs_io_req_retry_count | bigint | Number of OBS I/O request retries. Unit: times. |
| obs_io_req_rate_limit_count | bigint | Rate limit count of OBS I/O requests. Unit: times. |
pg_get_actor_stat()
Description: Obtains statistics about some monitoring items, including creating a CN, starting a CN, creating a session, adding a statement to a queue, executing a statement, writing a result set, obtaining the execution status, and retrieving the execution result. The statistics are recorded each time one of these events occurs.
Return type:
| Column | Type | Description |
|---|---|---|
| event_name | text | Name of a monitoring item. |
| object_name | text | Monitoring item ID. |
| start_time | timestamp with time zone | Start time of a monitoring item. |
| end_time | timestamp with time zone | End time of a monitoring item. |
| comment | text | Content of the comment. |
obs_get_access_label()
Description: Obtains the permissions of a specified OBS path.
Return type:
| Column | Type | Description |
|---|---|---|
| obs_path | text | OBS path |
| access_label | text | Permissions of the OBS path |
read_external_table_file()
Description: Parses external table files in ORC or Parquet format. If a file cannot be queried using SELECT due to version differences or data producer issues, you can use this function for diagnosis and analysis.
The input parameters are as follows.
| Column | Type | Description |
|---|---|---|
| tablename | text | Name of the target foreign table, which must be in Parquet, ORC, or Iceberg format |
| filename | text | Target file path, which must end with .orc or .parquet |
| target | text | Information of the file to be obtained. The value can be meta/m (metadata), statistics/s (statistics), contents/c (file content), meta -v/m -v (detailed metadata), or statistics -i/s -i (statistics including row indexes). |
| num | int | Used together with the third parameter to specify whether to obtain all (0) or part of the information |
Return type: text
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | select * from read_external_table_file('test0508','/******/30f16dfe-a7dc-487b-a285-752aeaebde72.parquet','m -v',0); read_external_table_file ---------------------------------------------------------------------------------------------------------------- { + "FileName": "/******/30f16dfe-a7dc-487b-a285-752aeaebde72.parquet", + "Version": "2.6", + "CreatedBy": "parquet-cpp-arrow version 17.0.0", + "TotalRows": "1", + "NumberOfRowGroups": "1", + "NumberOfRealColumns": "1", + "NumberOfColumns": "1", + "Columns": [ + { + "Id": "0", + "Name": "a", + "PhysicalType": "INT32", + "ConvertedType": "INT_32", + "LogicalType": {"Type": "Int", "bitWidth": 32, "isSigned": true} + } + ], + "RowGroups": [ + { + "Id": "0", + "Rows": "1", + "TotalBytes": "44", + "TotalCompressedBytes": "48", + "FileOffset": "4", + "ColumnChunks": [ + {"Id": "0", + "Values": "1", + "Compression": "SNAPPY", + "Encodings": "PLAIN RLE RLE_DICTIONARY ", + "UncompressedSize": "44", + "CompressedSize": "48", + } + ] + } + ] + } + (1 row) |
pg_get_statistics()
Description: Queries table statistics.
Input parameter description: table name (A schema can be specified.)
The returned value descriptions are as follows.
| Column | Type | Description |
|---|---|---|
| column_name | text | Column name |
| null_fraction | float4 | Proportion of NULL values. The value ranges from 0 to 1. For example, 0.25 indicates that 25% of the values in the column are NULL. |
| avg_width | int4 | Average column width in bytes. For example, the width is 4 for int4 and depends on the content for text. |
| distinct | float4 | Number of distinct values. A positive number indicates an absolute quantity, and a negative number indicates the proportion of the number of distinct values to the total number of rows. For example, –0.5 indicates that about 50% of the values are different from each other. |
| mcv_values | text | List of most common values. If no data is available, NULL is returned. |
| mcv_freqs | text | List of occurrence frequencies of the most common values. Each frequency matches a value in mcv_values. If no data is available, NULL is returned. |
| histogram_bounds | text | List of boundary values of a histogram. The column value range is divided into equal-frequency buckets. If no data is available, NULL is returned. |
pg_get_partition_statistics()
Description: Queries partition statistics.
The input parameters are as follows.
| Column | Type | Mandatory | Default Value | Description |
|---|---|---|---|---|
| table_name | text | Yes | - | Name of a partitioned table (A schema can be specified.) |
| partition_values | ARRAY | Yes | - | Array of partition key values |
| spec_id | int8 | No | 0 | Partition ID of an Iceberg table |
The returned value descriptions are as follows.
| Column | Type | Description |
|---|---|---|
| column_name | text | Column name |
| null_fraction | float4 | Proportion of NULL values. The value ranges from 0 to 1. For example, 0.25 indicates that 25% of the values in the column are NULL. |
| avg_width | int4 | Average column width in bytes. For example, the width is 4 for int4 and depends on the content for text. |
| distinct | float4 | Number of distinct values. A positive number indicates an absolute quantity, and a negative number indicates the proportion of the number of distinct values to the total number of rows. For example, –0.5 indicates that about 50% of the values are different from each other. |
| mcv_values | text | List of most common values. If no data is available, NULL is returned. |
| mcv_freqs | text | List of occurrence frequencies of the most common values. Each frequency matches a value in mcv_values. If no data is available, NULL is returned. |
| histogram_bounds | text | List of boundary values of a histogram. The column value range is divided into equal-frequency buckets. If no data is available, NULL is returned. |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 1. SELECT * FROM pg_get_statistics('my_table'); column_name | null_fraction | avg_width | distinct | mcv_values | mcv_freqs | histogram_bounds -------------+---------------+-----------+----------+-------------+-----------------+------------------ id | 0 | 4 | -1 | NULL | NULL | 1, 50, 100 name | 0.1 | 16 | -0.5 | Alice, Bob | 0.3, 0.2 | NULL status | 0 | 4 | 3 | active | 0.6 | NULL (1 row) 2. SELECT * FROM pg_get_partition_statistics('iceberg_table', ARRAY['2026-01-01', '3'], 0); column_name | null_fraction | avg_width | distinct | mcv_values | mcv_freqs | histogram_bounds -------------+---------------+-----------+----------+------------+-----------+------------------ x | 0 | 4 | -1 | NULL | NULL | 1, 2, 3 a | 0 | 10 | -0.8 | 123456789 | 0.4 | NULL b | 0 | 4 | 1 | NULL | NULL | NULL (1 row) |
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot