SQL statistics
Job details
Name: | SQL statistics |
Platform: | Mysql |
Category: | Performance |
Premium package: | SQL Performance package |
Description: | Collects performance statistics for SQL statements. |
Long description: | Collects performance statistics for SQL statements from performance_schema.events_statements_summary_by_digest table. |
Version: | 1.4 |
Default schedule: | 0,5,10,15,20,25,30,35,40,45,50,55 * * * |
Requires engine install: | Yes |
Compatibility tag: | .[type=‘instance’ & is_mysql_branch=‘1′]/.[hasengine=‘YES’ & global_status_performance_schema = ‘1′ & maj_version > ‘5.6′] |
Parameters
Name | Default value | Description |
---|---|---|
history threshold | 7 | The maximum number of day to kept statistics for in the historic tables. |
dbwatch database max size | 5000 | Maximum dbwatch database size (in MB). |
collect internal statistics | 30 | How often (in minutes) size of internal objects should be checked. “SQL statistics” job collects a large amount of data in the dbWatch schema tables, so it is important to keep track of space usage in the dbWatch database. |
SQL repository max size | 80 | Maximum space consumption (in percentage) of maximum size of the dbWatch database for internal/repository objects that contain statistics for SQL statements. |
min TIMER_WAIT | 1000 | Minimum TIMER_WAIT value (per execution) for a SQL statement to be registered into history tables (repository tables). |
return status | 1 | Return status value (ALARM – 2, WARNING – 1, or OK – 0) when reached maximum space consumption (in percentage) of maximum size of the dbWatch database (parameter “SQL repository max size”) |
Job Summary
- Purpose: The purpose of this job is to collect comprehensive performance statistics for SQL statements executed on the MySQL database, utilizing the performance_schema’s event statements summary by digest.
- Why: Monitoring SQL statement performance is crucial for identifying bottlenecks, inefficient queries, and opportunities for optimization. The detailed statistics help in understanding system behavior and ensure database performance stability.
- Manual checking: Manual checking can be done by directly querying the MySQL performance schema with the appropriate SQL commands to retrieve statistics:
SELECT * FROM performance_schema.events_statements_summary_by_digest;
Implementation Details
The job consists of several steps to gather statistics, manage historical data, and ensure proper handling of the database space:
- Creating and managing tables and indices for current and historical SQL statistics.
- Custom procedures to insert and update statistics records into these tables.
- Conditional execution based on parameters set for history threshold, maximum DB size, and interval for collecting internal statistics.
- Error handling and clean-up mechanisms to maintain data integrity and system stability.
Key Components
- “dbw_sql_stat_current” – A table maintained for real-time SQL statistics.
- “dbw_sql_stat_histr” – A table to retain historical summary data about SQL statements.
- “dbw_sql_text_histr” – A historical table for the text of the SQL statements.
- “dbw_internal_sql_stat_histr” and “dbw_internal_sql_size_histr” – Internal tables to monitor SQL and index sizes over time.
- “dbw_sql_statistics”, “dbw_sql_internal_clean” – Procedures to populate, clean and manage the statistical data.
Cleanup on Fail
- In the event of a job failure, specific cleanup operations are initiated to remove temporary or corrupt data ensuring system cleanliness.
DROP TABLE statements are utilized to clear artifacts such as:
drop table dbw_sql_statistics_histr;
drop table dbw_sql_statistics_last;
drop table dbw_sql_stat_current;
...
Dependencies Check
A series of dependency checks ensure all required objects are in place for the job to function correctly. Failure in any dependencies triggers a cleanup:
- Main procedures and several auxiliary SQL and history tables are checked before the job runs.
Parameters Overview
The following parameters are crucial for job configuration but are excluded from deep analysis as per request:
- history threshold
- dbwatch database max size
- collect internal statistics
- SQL repository max size
- min TIMER_WAIT
- return status
Reporting Template
The execution results populate internal tables that can be visualized through predefined reports, proving insights like:
- SQL statistics overview
- Internal table and index size history
This monitoring job is vital for maintaining optimal performance and operational health of MySQL database environments, especially those managing extensive data transactions and complex query operations.