25.15 Performance Schema 系统变量

性能架构实现了几个提供配置信息的系统变量:

mysql> SHOW VARIABLES LIKE 'perf%';
+----------------------------------------------------------+-------+
| Variable_name                                            | Value |
+----------------------------------------------------------+-------+
| performance_schema                                       | ON    |
| performance_schema_accounts_size                         | -1    |
| performance_schema_digests_size                          | 10000 |
| performance_schema_events_stages_history_long_size       | 10000 |
| performance_schema_events_stages_history_size            | 10    |
| performance_schema_events_statements_history_long_size   | 10000 |
| performance_schema_events_statements_history_size        | 10    |
| performance_schema_events_transactions_history_long_size | 10000 |
| performance_schema_events_transactions_history_size      | 10    |
| performance_schema_events_waits_history_long_size        | 10000 |
| performance_schema_events_waits_history_size             | 10    |
| performance_schema_hosts_size                            | -1    |
| performance_schema_max_cond_classes                      | 80    |
| performance_schema_max_cond_instances                    | -1    |
| performance_schema_max_digest_length                     | 1024  |
| performance_schema_max_file_classes                      | 50    |
| performance_schema_max_file_handles                      | 32768 |
| performance_schema_max_file_instances                    | -1    |
| performance_schema_max_index_stat                        | -1    |
| performance_schema_max_memory_classes                    | 320   |
| performance_schema_max_metadata_locks                    | -1    |
| performance_schema_max_mutex_classes                     | 200   |
| performance_schema_max_mutex_instances                   | -1    |
| performance_schema_max_prepared_statements_instances     | -1    |
| performance_schema_max_program_instances                 | -1    |
| performance_schema_max_rwlock_classes                    | 40    |
| performance_schema_max_rwlock_instances                  | -1    |
| performance_schema_max_socket_classes                    | 10    |
| performance_schema_max_socket_instances                  | -1    |
| performance_schema_max_sql_text_length                   | 1024  |
| performance_schema_max_stage_classes                     | 150   |
| performance_schema_max_statement_classes                 | 192   |
| performance_schema_max_statement_stack                   | 10    |
| performance_schema_max_table_handles                     | -1    |
| performance_schema_max_table_instances                   | -1    |
| performance_schema_max_table_lock_stat                   | -1    |
| performance_schema_max_thread_classes                    | 50    |
| performance_schema_max_thread_instances                  | -1    |
| performance_schema_session_connect_attrs_size            | 512   |
| performance_schema_setup_actors_size                     | -1    |
| performance_schema_setup_objects_size                    | -1    |
| performance_schema_users_size                            | -1    |
+----------------------------------------------------------+-------+

可以在服务器启动时在命令行或选项文件中设置 Performance Schema 系统变量,并且可以在运行时设置许多变量。参见第 25.13 节“性能模式选项和变量引用”

如果未明确设置性能模式,则在服务器启动时,性能模式会自动调整其几个参数的值。有关更多信息,请参见第 25.3 节“性能架构启动配置”

Performance Schema 系统变量具有以下含义:

PropertyValue
Command-Line Format--performance-schema[={OFF|ON}]
System Variableperformance_schema
ScopeGlobal
DynamicNo
TypeBoolean
Default ValueON

此变量的值为ONOFF,以指示是否启用了性能模式。默认情况下,值为ON。在服务器启动时,可以指定此变量,不带任何值或ON或 1 的值以启用它,或指定OFF或 0 的值以禁用它。

即使禁用了性能架构,它也会 continue 填充global_variablessession_variablesglobal_statussession_statustable。根据show_compatibiliy_56系统变量的设置,必要时会发生这种情况,以允许从这些 table 中提取SHOW VARIABLESSHOW STATUS语句的结果。

PropertyValue
Command-Line Format--performance-schema-accounts-size=#
System Variableperformance_schema_accounts_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)
Minimum Value-1(table 示自动缩放;请勿分配此 Literals 值)
Maximum Value1048576

accountstable 中的行数。如果此变量为 0,则性能架构将不维护accountstable 中的连接统计信息或status_by_accounttable 中的状态变量信息。

PropertyValue
Command-Line Format--performance-schema-digests-size=#
System Variableperformance_schema_digests_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)
Minimum Value-1
Maximum Value1048576

events_statements_summary_by_digesttable 中的最大行数。如果超过了该最大值,则无法检测到摘要,则性能架构将使Performance_schema_digest_lost status 变量递增。

有关语句摘要的更多信息,请参见第 25.10 节“性能模式语句摘要”

PropertyValue
Command-Line Format--performance-schema-events-stages-history-long-size=#
System Variableperformance_schema_events_stages_history_long_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_stages_history_longtable 中的行数。

PropertyValue
Command-Line Format--performance-schema-events-stages-history-size=#
System Variableperformance_schema_events_stages_history_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_stages_historytable 中每个线程的行数。

PropertyValue
Command-Line Format--performance-schema-events-statements-history-long-size=#
System Variableperformance_schema_events_statements_history_long_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_statements_history_longtable 中的行数。

PropertyValue
Command-Line Format--performance-schema-events-statements-history-size=#
System Variableperformance_schema_events_statements_history_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_statements_historytable 中每个线程的行数。

PropertyValue
Command-Line Format--performance-schema-events-transactions-history-long-size=#
System Variableperformance_schema_events_transactions_history_long_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_transactions_history_longtable 中的行数。

PropertyValue
Command-Line Format--performance-schema-events-transactions-history-size=#
System Variableperformance_schema_events_transactions_history_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_transactions_historytable 中每个线程的行数。

PropertyValue
Command-Line Format--performance-schema-events-waits-history-long-size=#
System Variableperformance_schema_events_waits_history_long_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_waits_history_longtable 中的行数。

PropertyValue
Command-Line Format--performance-schema-events-waits-history-size=#
System Variableperformance_schema_events_waits_history_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

events_waits_historytable 中每个线程的行数。

PropertyValue
Command-Line Format--performance-schema-hosts-size=#
System Variableperformance_schema_hosts_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)
Minimum Value-1(table 示自动缩放;请勿分配此 Literals 值)
Maximum Value1048576

hoststable 中的行数。如果此变量为 0,则性能架构将不维护hoststable 中的连接统计信息或status_by_hosttable 中的状态变量信息。

PropertyValue
Command-Line Format--performance-schema-max-cond-classes=#
System Variableperformance_schema_max_cond_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value80
Minimum Value0
Maximum Value256

条件仪器的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-cond-instances=#
System Variableperformance_schema_max_cond_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

已检测条件对象的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-digest-length=#
System Variableperformance_schema_max_digest_length
ScopeGlobal
DynamicNo
TypeInteger
Default Value1024
Minimum Value0
Maximum Value1048576

每个语句保留的最大内存字节数,用于计算性能模式中的规范化语句摘要值。此变量与max_digest_length有关;请参阅第 5.1.7 节“服务器系统变量”中该变量的描述。

有关语句摘要的更多信息,包括有关内存使用的注意事项,请参见第 25.10 节“性能模式语句摘要”

PropertyValue
Command-Line Format--performance-schema-max-file-classes=#
System Variableperformance_schema_max_file_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value80
Minimum Value0
Maximum Value256

文件工具的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-file-handles=#
System Variableperformance_schema_max_file_handles
ScopeGlobal
DynamicNo
TypeInteger
Default Value32768

已打开文件对象的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

performance_schema_max_file_handles的值应大于open_files_limit的值:open_files_limit影响服务器可以支持的打开文件句柄的最大数量,而performance_schema_max_file_handles影响可以检测这些文件句柄的数量。

PropertyValue
Command-Line Format--performance-schema-max-file-instances=#
System Variableperformance_schema_max_file_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

已检测文件对象的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-index-stat=#
System Variableperformance_schema_max_index_stat
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

性能架构为其维护统计信息的最大索引数。如果超过此最大值,以至于索引统计信息丢失,则性能架构将使Performance_schema_index_stat_lost状态变量递增。默认值是使用performance_schema_max_table_instances值自动调整大小的。

PropertyValue
Command-Line Format--performance-schema-max-memory-classes=#
System Variableperformance_schema_max_memory_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value320

内存仪器的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-metadata-locks=#
System Variableperformance_schema_max_metadata_locks
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

元数据锁定工具的最大数量。此值控制metadata_lockstable 的大小。如果超出此最大值,使得无法检测到元数据锁,则性能架构将使Performance_schema_metadata_lock_lost status 变量递增。

PropertyValue
Command-Line Format--performance-schema-max-mutex-classes=#
System Variableperformance_schema_max_mutex_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value200
Minimum Value0
Maximum Value256

互斥乐器的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-mutex-instances=#
System Variableperformance_schema_max_mutex_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

已检测的互斥对象的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-prepared-statements-instances=#
System Variableperformance_schema_max_prepared_statements_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

prepared_statements_instancestable 中的最大行数。如果超过了该最大值,使得无法检测到准备好的语句,则性能架构将使Performance_schema_prepared_statements_lost status 变量递增。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

该变量的默认值根据max_prepared_stmt_count系统变量的值自动调整大小。

PropertyValue
Command-Line Format--performance-schema-max-rwlock-classes=#
System Variableperformance_schema_max_rwlock_classes
ScopeGlobal
DynamicNo
TypeInteger
默认值(≥5.7.25)50
默认值(≤5.7.24)40
Minimum Value0
Maximum Value256

rwlock 仪器的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-program-instances=#
System Variableperformance_schema_max_program_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

性能模式为其维护统计信息的最大存储程序数。如果超过该最大值,则性能架构将使Performance_schema_program_lost状态变量递增。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-rwlock-instances=#
System Variableperformance_schema_max_rwlock_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

检测的 rwlock 对象的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-socket-classes=#
System Variableperformance_schema_max_socket_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value10
Minimum Value0
Maximum Value256

socket 乐器的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-socket-instances=#
System Variableperformance_schema_max_socket_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

已检测的套接字对象的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-sql-text-length=#
System Variableperformance_schema_max_sql_text_length
ScopeGlobal
DynamicNo
TypeInteger
Default Value1024
Minimum Value0
Maximum Value1048576

用于在events_statements_currentevents_statements_historyevents_statements_history_long语句事件 table 的SQL_TEXT列中存储 SQL 语句的最大字节数。超过performance_schema_max_sql_text_length的所有字节都将被丢弃,并且不会出现在SQL_TEXT列中。只有在此列中无法区分许多初始字节之后,语句才有所不同。

减小performance_schema_max_sql_text_length值会减少内存使用量,但如果仅在末尾有所不同,则会导致更多语句变得难以区分。增加该值会增加内存使用量,但可以区分更长的语句。

PropertyValue
Command-Line Format--performance-schema-max-stage-classes=#
System Variableperformance_schema_max_stage_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value150
Minimum Value0
Maximum Value256

舞台乐器的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-statement-classes=#
System Variableperformance_schema_max_statement_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

声明工具的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

默认值是在服务器构建时根据 Client 端/服务器协议中的命令数量和服务器支持的 SQL 语句类型的数量计算的。

除非将其设置为 0 以禁用所有语句检测并保存与之关联的所有内存,否则请勿更改此变量。将变量设置为默认值以外的非零值没有好处。特别是,大于默认值的值将导致需要分配更多的内存。

PropertyValue
Command-Line Format--performance-schema-max-statement-stack=#
System Variableperformance_schema_max_statement_stack
ScopeGlobal
DynamicNo
TypeInteger
Default Value10

性能模式为其维护统计信息的嵌套存储程序调用的最大深度。当超过此最大值时,性能模式将为每个执行的存储程序语句增加Performance_schema_nested_statement_lost状态变量。

PropertyValue
Command-Line Format--performance-schema-max-table-handles=#
System Variableperformance_schema_max_table_handles
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

已打开 table 格对象的最大数量。此值控制table_handlestable 的大小。如果超过了该最大值,使得无法检测到 table 句柄,则性能架构将使Performance_schema_table_handles_lost状态变量递增。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-table-instances=#
System Variableperformance_schema_max_table_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

检测 table 对象的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-table-lock-stat=#
System Variableperformance_schema_max_table_lock_stat
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)

性能模式为其维护锁统计信息的最大 table 数。如果超过此最大值,导致 table 锁统计信息丢失,则性能架构将使Performance_schema_table_lock_stat_lost status 变量递增。

PropertyValue
Command-Line Format--performance-schema-max-thread-classes=#
System Variableperformance_schema_max_thread_classes
ScopeGlobal
DynamicNo
TypeInteger
Default Value50
Minimum Value0
Maximum Value256

线程工具的最大数量。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

PropertyValue
Command-Line Format--performance-schema-max-thread-instances=#
System Variableperformance_schema_max_thread_instances
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

检测的线程对象的最大数量。该值控制threadstable 的大小。如果超出此最大值,导致无法检测线程,则性能架构将使Performance_schema_thread_instances_lost status 变量递增。有关如何设置和使用此变量的信息,请参见第 25.7 节“性能模式状态监视”

max_connections系统变量影响服务器中可以运行的线程数。 performance_schema_max_thread_instances影响可以检测多少个正在运行的线程。

variables_by_threadstatus_by_threadtable 仅包含有关前台线程的系统和状态变量信息。如果不是所有线程都由性能架构进行检测,则该 table 将丢失一些行。在这种情况下,Performance_schema_thread_instances_lost状态变量将大于零。

PropertyValue
Command-Line Format--performance-schema-session-connect-attrs-size=#
System Variableperformance_schema_session_connect_attrs_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动调整大小;请勿分配此 Literals 值)
Minimum Value-1
Maximum Value1048576

每个线程保留来保留连接属性键值对的预分配内存量。如果 Client 端发送的连接属性数据的总大小大于此数量,那么性能架构将截断该属性数据,递增Performance_schema_session_connect_attrs_lost状态变量,并将一条消息写入错误日志,以指示如果log_error_verbosity系统变量值发生了截断大于 1.

服务器启动时会自动调整默认值performance_schema_session_connect_attrs_size。该值可能很小,因此如果发生截断(Performance_schema_session_connect_attrs_lost变为非零),则可能希望将performance_schema_session_connect_attrs_size显式设置为更大的值。

尽管允许的最大performance_schema_session_connect_attrs_size值为 1MB,但有效的最大值为 64KB,因为服务器对它将接受的连接属性数据的总大小施加了 64KB 的限制。如果 Client 端尝试发送超过 64KB 的属性数据,则服务器将拒绝连接。有关更多信息,请参见第 25.12.9 节“性能架构连接属性 table”

PropertyValue
Command-Line Format--performance-schema-setup-actors-size=#
System Variableperformance_schema_setup_actors_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

setup_actorstable 中的行数。

PropertyValue
Command-Line Format--performance-schema-setup-objects-size=#
System Variableperformance_schema_setup_objects_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)

setup_objectstable 中的行数。

PropertyValue
Command-Line Format--performance-schema-users-size=#
System Variableperformance_schema_users_size
ScopeGlobal
DynamicNo
TypeInteger
Default Value-1(table 示自动缩放;请勿分配此 Literals 值)
Minimum Value-1(table 示自动缩放;请勿分配此 Literals 值)
Maximum Value1048576

userstable 中的行数。如果此变量为 0,则性能架构将不维护userstable 中的连接统计信息或status_by_usertable 中的状态变量信息。