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 parameters below 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.

Parameter type: Boolean.

Unit: none

Value range:

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

Default value: on

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 reclamation capability of the storage engine is affected, causing space expansion.

track_counts

Parameter description: Specifies whether to collect statistics about database activities. 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

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 reclamation 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.

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

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.

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 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.

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.

Parameter 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

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 on Windows task manager 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.

enable_gsstat_cache

Parameter description: Specifies whether to enable cache acceleration for PgStat functions.

PgStat functions include pg_stat_get_numscans, pg_stat_get_tuples_returned, pg_stat_get_tuples_fetched, pg_stat_get_tuples_inserted, pg_stat_get_tuples_updated, pg_stat_get_tuples_deleted, pg_stat_get_tuples_hot_updated, pg_stat_get_live_tuples, pg_stat_get_dead_tuples, pg_stat_get_autovacuum_count, pg_stat_get_autoanalyze_count, pg_stat_get_blocks_fetched, pg_stat_get_blocks_hit, pg_timestamp stat_get_last_autoanalyze_time, pg_timestamp stat_get_last_autovacuum_time, and pg_timestamp stat_get_last_updated.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The cache acceleration function is enabled for PgStat functions.
  • off: The cache acceleration function is disabled for PgStat functions.

Default value: off

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

Setting suggestion: If this parameter is disabled and the query of PgStat-related views using the preceding functions is slow, you are advised to enable this parameter.

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.

Parameter type: integer.

Unit: minute

Value range: 0 to 1440

Default value: 30

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.

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

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.

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

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.

Parameter type: Boolean.

Unit: none

Value range:

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

Default value: on

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.

If this parameter is disabled, the query result is 0.