Updated on 2025-05-29 GMT+08:00

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 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 views pg_stats and pg_statistic. The following parameters are used to set the statistics collection feature in the server scope:

track_activities

Parameter description: Specifies whether to collect statistics about the commands that are being executed in each session. For a stored procedure, if this parameter is enabled, you can view the PERFORM statement, stored procedure calling statement, SQL statement, and OPEN CURSOR statement that are being executed in the stored procedure in the pg_stat_activity view. This parameter can be set at the PDB level.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The statistics collection function is enabled.
  • off: The statistics collection function is disabled.

Default value: on. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a SUSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: If this parameter is set to off, the space recycling capability of the storage engine is affected, causing space expansion.

track_counts

Parameter description: Specifies whether to collect statistics about database activities. This parameter can be set at the PDB level. Database statistics are required when the autovacuum process checks for databases that need to be vacuumed. Therefore, the default value is set to on.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The statistics collection function is enabled.
  • off: The statistics collection function is disabled.

Default value: on. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a SUSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: If this parameter is set to off, the space recycling capability of the storage engine is affected, causing space expansion.

track_procedure_sql

Parameter description: Specifies whether the SQL statements that are being executed in the stored procedure are printed in the query column in the pg_stat_activity system catalog. This parameter can be set at the PDB level.

Parameter type: Boolean.

Unit: none

Value range:

  • on: When a stored procedure is called, the statements that are being executed by the stored procedure are printed in the query column of pg_stat_activity.
  • off: When a stored procedure is called, only statements for calling the stored procedure are printed in the query column of pg_stat_activity.

Default value: on. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

track_io_timing

Parameter description: Specifies whether to collect statistics about I/O timing in the database. The I/O timing statistics can be queried by using the pg_stat_database parameter. When this parameter is enabled, the collector repeatedly queries the OS information at the current time, which may cause significant cost on some platforms. Therefore, the default value is off. This parameter can be set at the PDB level.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The statistics collection function is enabled.
  • off: The statistics collection function is disabled.

Default value: off. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a SUSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

track_functions

Parameter description: Specifies whether to collect statistics of the number and duration of function calls. This parameter can be set at the PDB level.

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

Value type: enumerated type

Unit: none

Value range:

  • pl: Only procedural language functions are traced.
  • all: SQL language functions are traced.
  • none: The function tracing function is disabled.

Default value: none. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a SUSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

track_activity_query_size

Parameter description: Specifies byte counts of the current running commands used to trace each active session. If the actual number of bytes in a command is greater than the value of this parameter, the command is truncated.

Parameter type: integer

Unit: byte

Value range: 100 to 102400

Default value: 1024

Setting method: This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Set this parameter based on the actual service scenario.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

update_process_title

Parameter description: Specifies whether to control statistics updated with a thread name each time the server receives a new SQL statement.

The thread name can be viewed by running the ps command.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The statistics collection function is enabled.
  • off: The statistics collection function is disabled.

Default value: off

Setting method: This is a fixed INTERNAL parameter. It can be viewed but cannot be modified.

Setting suggestion: This parameter can only be viewed.

Risks and impacts of improper settings: none

stats_temp_directory

Parameter description: Specifies the directory for storing temporary statistics. Only the sysadmin user can access this parameter.

If a RAM-based file system directory is used, the actual I/O cost can be lowered and the performance can be improved.

Parameter type: string.

Unit: none

Value range: valid directory.

Default value: "pg_stat_tmp"

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

track_thread_wait_status_interval

Parameter description: Specifies the interval of collecting the thread status information. This parameter can be set at the PDB level.

Parameter type: integer

Unit: minute

Value range: 0 to 1440

Default value: 30. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a SUSET parameter. Set it based on instructions provided in Table 1. For example, if this parameter is set to 100 without a unit, it indicates 100 minutes. If this parameter is set to 1d, it indicates 1 day. The unit must be min, h, or d if required.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

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. This parameter can be set at the PDB level.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The time when an operation is performed on table data will be recorded.
  • off: The time when an operation is performed on table data will not be recorded.

Default value: on. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

enable_plan_trace

Parameter description: Specifies whether to enable the PLAN TRACE feature for the database. This parameter cannot be set globally by running the gs_guc command. It can be set only by running the set command in a connected session.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The PLAN TRACE feature is enabled.
  • off: The PLAN TRACE feature is disabled.

Default value: off

Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

plan_collect_thresh

Parameter description: Collects statistics about the plans that are being executed in each session. This parameter can be set at the PDB level.

Parameter type: integer

Unit: none

Value range: –1 to 2147483647

  • –1: Plans that are being executed are not collected.
  • 0: If the current SQL execution time is greater than or equal to the value of log_min_duration_statement and the total number of tuples processed by all operators in the plan is greater than or equal to 10000, the system starts to collect plans in running state. Each time the total number of tuples processed by all operators exceeds 10000, a collection is performed.
  • Value greater than 0: When the total number of tuples incrementally returned by all operators in a plan is greater than or equal to the value of this parameter, plans that are being executed are collected once.

Default value: 0. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a SUSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

track_sql_count

Parameter description: Specifies whether to collect statistics about the statements (SELECT, INSERT, UPDATE, MERGE INTO, and DELETE) that are being executed in a session. This parameter can be set at the PDB level.

In the x86-based centralized deployment scenario, the hardware configuration specifications are 32-core CPU and 256 GB memory. When the Benchmark SQL 5.0 tool is used to test performance, the performance fluctuates by about 0.8% by enabling or disabling this parameter.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The statistics collection function is enabled.
  • off: The statistics collection function is disabled.

Default value: on. In the PDB scenario, if this parameter is not set, the global setting is inherited.

Setting method: This is a SUSET parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

  • The track_sql_count parameter is restricted by the track_activities parameter.
    • If track_activities is enabled and track_sql_count is disabled, a warning message indicating that track_sql_count is disabled will be displayed in logs when the gs_sql_count view is queried.
    • If both track_activities and track_sql_count are disabled, two warning messages indicating that track_activities is disabled and track_sql_count is disabled will be displayed in logs when the views are queried.
    • If track_activities is disabled and track_sql_count is enabled, a warning message indicating that track_activities is disabled will be displayed in logs when the views are queried.
  • If this parameter is disabled, the query result is 0.