Query and Index Statistics Collector

The query and index statistics collector is used to collect statistics during database running. The statistics include the times of inserting and updating a table and an index, the number of disk blocks and tuples, and the time required for the last cleanup and analysis on each table. The statistics can be viewed by querying system view families pg_stats and pg_statistic. The following parameters are used to set the statistics collection feature in the server scope.

track_activities

Parameter description: Collects statistics about the commands that are being executed in session.

Type: SUSET

Value range: Boolean

Default value: on

track_counts

Parameter description: Collects statistics about data activities.

Type: SUSET

Value range: Boolean

When the database to be cleaned up is selected from the AutoVacuum automatic cleanup process, the database statistics are required. In this case, the default value is set to on.

Default value: on

track_io_timing

Parameter description: Collects statistics about I/O invoking timing in the database. The I/O timing statistics can be queried by using the pg_stat_database parameter.

Type: SUSET

Value range: Boolean

Default value: off

track_functions

Parameter description: Collects statistics about invoking times and duration in a function.

Type: SUSET

When the SQL functions are set to inline functions queried by the invoking, these SQL functions cannot be traced no matter these functions are set or not.

Value range: enumerated values

Default value: none

update_process_title

Parameter description: Collects statistics updated with a process name each time the server receives a new SQL statement.

The process name can be viewed on Windows task manager by running the ps command.

Type: SUSET

Value range: Boolean

Default value: off

track_thread_wait_status_interval

Parameter description: Specifies the interval of collecting the thread status information periodically.

Type: SUSET

Value range: an integer ranging from 0 to 1440, in minutes.

Default value: 30min

enable_save_datachanged_timestamp

Parameter description: Specifies whether to record the time when INSERT, UPDATE, DELETE, or EXCHANGE/TRUNCATE/DROP PARTITION is performed on table data.

Type: USERSET

Value range: Boolean

Default value: on

enable_save_dataaccess_timestamp

Parameter description: Specifies whether to record the last access time of a table. This parameter is supported only by 8.2.1.210 and later cluster versions.

Type: USERSET

Value range: Boolean

Default value: off

instr_unique_sql_count

Parameter description: Specifies whether to collect Unique SQL statements and the maximum number allowed.

Type: SIGHUP

Value range: an integer ranging from 0 to INT_MAX

Default value: 0

If a new value is smaller than the original value, the Unique SQL statistics collected on the CN will be cleared.

track_sql_count

Parameter description: Specifies whether to collect statistics on the number of the SELECT, INSERT, UPDATE, DELETE, and MERGE INTO statements that are being executed in each session, the response time of the SELECT, INSERT, UPDATE, and DELETE statements, and the number of DDL, DML, and DCL statements.

Type: SUSET

Value range: Boolean

Default value: on

  • The track_sql_count parameter is restricted by the track_activities parameter.
    • If track_activities is set to on and track_sql_count is set to off, a warning message indicating that track_sql_count is disabled will be displayed when the view gs_sql_count, pgxc_sql_count, gs_workload_sql_count, pgxc_workload_sql_count, global_workload_sql_count, gs_workload_sql_elapse_time, pgxc_workload_sql_elapse_time, or global_workload_sql_elapse_time are queried.
    • If both track_activities and track_sql_count are set to off, two logs indicating that track_activities is disabled and track_sql_count is disabled will be displayed when the views are queried.
    • If track_activities is set to off and track_sql_count is set to on, a log indicating that track_activities is disabled will be displayed when the views are queried.
  • If this parameter is disabled, querying the view returns 0.

enable_parallel_analyze

Parameter description: Specifies whether to use parallel sampling for internal and foreign table analysis. This parameter is supported only by clusters of version 9.1.0 or later.

Type: USERSET

Value range: Boolean

Default value: true

  • When enable_parallel_analyze is set to true and analyzing foreign tables, try to avoid adding NOT NULL constraints to the target foreign table columns to prevent constraint failure due to data source changes. Currently, parallel sampling does not support materialized views. If analyze fails due to such reasons, set this parameter to false.
  • Currently, parallel sampling only supports analyzing ordinary column-store internal tables. This optimization does not take effect when the internal table uses hstore/hstore_opt or is declared as a replicated table.
  • Currently, parallel sampling only supports analyzing foreign tables stored in parquet/orc format. This optimization does not take effect when the foreign table is in another format.

parallel_analyze_workers

Parameter description: Specifies the number of concurrent threads for parallel analyze sampling. This parameter is supported only by clusters of version 9.1.0 or later.

Type: USERSET

Value range: an integer ranging from 0 to 64

Default value: 10

The value of this parameter should correspond to the cluster load. When the cluster load is low, you can increase the parameter value appropriately based on the cluster configuration to further improve the efficiency of analyze execution.

analyze_sample_multiplier

Parameter description: Specifies the multiplier for the stripe sampling rate used in analyzing foreign tables. This parameter is supported only by clusters of version 9.1.0 or later.

Type: SUSET

Value range: an integer ranging from 0 to 100. 0 indicates that the stripe sampling rate is 100%.

Default value: 3