sys System Library Notes (a) - Introduction and Quick Start

Series of articles making reference to "MySQL Performance Optimization Pyramid law", deleted the book and repeated explanation is too complex some explanation, please refer to the full version of the original book.

In front of a series of notes presented performance_schema library system, put it in front of one of the reasons is because it is the source of data sys system libraries. This series is based on MySQL 5.7.18 version finishing

 

A, SYS system library premise

Before using sys system libraries, we need to ensure that the database environment meets the following conditions:

Version 1) MySQL 5.6 or higher

2)启用performance_schema(performance_schema=on)

3) To have full access to sys system libraries, users must have the following rights:

  • SELECT permission on all tables and views sys
  • Sys has EXECUTE privileges to all stored procedures and functions
  • Have INSERT, UPDATE permissions on the table sys_config
  • Sys system for certain libraries stored procedures and functions requires additional privileges, such as, ps_setup_save () stored procedure requires a temporary table related rights

4) have been associated with the object to perform a sys system library access permissions

  • Any performance_schema table is accessed sys system library needs to have SELECT privilege; To use the sys system libraries for performance_schema related tables to perform the update, you need to performance_schema related table UPDATE permissions
  • PROCESS privilege INFORMATION_SCHEMA.INNODB_BUFFER_PAGE table

5) To use the full functionality sys system libraries, you must enable certain performance_schema of instruments and consumers:

  • All wait instruments
  • All stage instruments
  • All statement instruments
  • For instruments enabled the type of event, also you need to enable the corresponding type of consumers (xxx_current and xxx_history_long)

You can use sys system libraries to enable all instruments and consumers need (details stored procedures can show create procedure procedure_name; see statement):

  • 启用所有wait instruments:CALL sys.ps_setup_enable_instrument('wait');
  • Enable all stage instruments: CALL sys.ps_setup_enable_instrument ( 'stage');
  • Enable all statement instruments: CALL sys.ps_setup_enable_instrument ( 'statement');
  • Enable all types of current events table: CALL sys.ps_setup_enable_consumer ( 'current');
  • Enable all event types history_long table: CALL sys.ps_setup_enable_consumer ( 'history_long');

note:

The default configuration performance_schema to meet most of the data collection sys system libraries. All instruments and performance will enable consumers above mentioned have an impact, it is best to enable only the required configuration. You can use CALL sys.ps_setup_reset_to_default (TRUE); quickly revert to the default configuration of performance_schema.

For more complex permission requirements, you can usually create an account with administrator privileges, of course, if you have a clear demand, that is another matter, but sys system libraries are usually provided to the DBA to use to troubleshoot certain problems, which under the inquiry involved more or less will have some impact on performance (mainly reflected in the performance overhead performance_schema functions implemented), in the case of unknown demand, not recommended to open these capabilities to use as a routine means of monitoring.

 

Two, sys system library first experience

You can switch to view under direct inquiries sys system libraries, as a lookup table in a library as follows:

# version视图可以查看sys 系统库和mysql server的版本号
mysql> USE sys;
mysql> SELECT * FROM version;
+ ------------- + ----------------- +
| sys_version | mysql_version |
+ ------------- + ----------------- +
| 1.5.0 | 5.7.9-debug-log |
+ ------------- + ----------------- +

sys contains many view the library system, the polymerization is calculated in various ways to display performance_schema table. Most of which are in pairs, two views of the same name, but the 'x $' character prefix with a view, for example: host_summary_by_file_io and x $ host_summary_by_file_io, summary statistics on behalf of the host in accordance with file I / O performance data, two accessing a data source view is the same, but the view create statement, the view without x $ is the correlation value data subjected to re-display unit conversion, x $ prefix with a view shows the raw data (picoseconds).

# 输出信息经过单位换算,可读性更高
mysql> SELECT * FROM host_summary_by_file_io;
+------------+-------+------------+
| host      | ios  | io_latency |
+------------+-------+------------+
| localhost  | 67570 | 5.38 s    |
| background |  3468 | 4.18 s    |
+------------+-------+------------+

# 带x$的视图显示原始的皮秒单位数值,对于程序或工具获取使用更易于数据处理
mysql> SELECT * FROM x$host_summary_by_file_io;
+------------+-------+---------------+
| host      | ios  | io_latency    |
+------------+-------+---------------+
| localhost  | 67574 | 5380678125144 |
| background |  3474 | 4758696829416 |
+------------+-------+---------------+

To see sys system library object definition statement, you can use the appropriate SHOW statement or INFORMATION_SCHEMA queries.

mysql> SHOW CREATE VIEW session;
mysql> SHOW CREATE FUNCTION format_bytes;

To see more readable format object definition statements, you can access files on various .sql database development system sys website https://github.com/mysql/mysql-sys, or use the mysqldump tool to export and mysqlpump sys library default , mysqldump and mysqlpump are not exported sys system libraries. To generate export file contains sys library system, the following command can be used to explicitly specify sys system library. Although you can export the view definition, but compared to the original definition statement is still missing a considerable part of the content, readability is better than just directly show create view:

mysqldump --databases --routines sys> sys_dump.sql
mysqlpump sys> sys_dump.sql
# 如果要重新导入sys 系统库,可以使用如下命令:
mysql < sys_dump.sql

 

Third, transaction reporting progress

Starting MySQL 5.7.9, sys system library view provides a progress report on the long-running transactions, and viewed through processlist session and view x $ prefix, which contains processlist background and foreground thread current event information, session is not included Daemon background thread to thread and command, as follows:

processlist
session
x$processlist
x$session

session view directly call processlist view and filter the background thread command to Daemon thread.

processlist thread linking the query threads, events_waits_current, events_stages_current, events_statements_current, events_transactions_current, sys.x $ memory_by_thread_by_current_bytes, session_connect_attrs table, so need to open the appropriate instruments and consumers, who otherwise did not open an information field corresponding to the column who is NULL, the field for trx_state to ACTIVE thread, progress can output percentage progress information, but only to support the progress of the event will be counted and printed.

-- 查看当前正在执行的语句进度信息
select * from session where conn_id!=connection_id() and trx_state='ACTIVE'\G;

*************************** 1. row ***************************
            thd_id: 47
          conn_id: 5
              user: admin@localhost
                db: sbtest
          command: Query
            state: alter table (merge sort)
              time: 29
current_statement: alter table sbtest1 add index i_c(c)
statement_latency: 29.34 s
          progress: 49.70  ------ 进度
      lock_latency: 4.34 ms
    rows_examined: 0
        rows_sent: 0
    rows_affected: 0
        tmp_tables: 0
  tmp_disk_tables: 0
        full_scan: NO
    last_statement: NULL
last_statement_latency: NULL
    current_memory: 4.52 KiB
        last_wait: wait/io/file/innodb/innodb_temp_file
last_wait_latency: 369.52 us
            source: os0file.ic:470
      trx_latency: 29.45 s
        trx_state: ACTIVE
    trx_autocommit: YES
              pid: 4667
      program_name: mysql
1 row in set (0.12 sec)


-- 查看已经执行完的语句相关统计信息
select * from session where conn_id!=connection_id() and trx_state='COMMITTED'\G;

*************************** 1. row ***************************
            thd_id: 47
          conn_id: 5
              user: admin@localhost
                db: sbtest
          command: Sleep
            state: NULL
              time: 372
current_statement: NULL
statement_latency: NULL
          progress: NULL ------ 已执行完、未启用、不支持进度显示的为null
      lock_latency: 4.34 ms
    rows_examined: 0
        rows_sent: 0
    rows_affected: 0
        tmp_tables: 0
  tmp_disk_tables: 0
        full_scan: NO
    last_statement: alter table sbtest1 add index i_c(c)
last_statement_latency: 1.61 m
    current_memory: 4.52 KiB
        last_wait: idle
last_wait_latency: Still Waiting
            source: socket_connection.cc:69
      trx_latency: 1.61 m
        trx_state: COMMITTED
    trx_autocommit: YES
              pid: 4667
      program_name: mysql
1 row in set (0.12 sec)

For stage events progress reporting requirements must be enabled events_stages_current consumers, need to be enabled to view the progress of the relevant instruments. E.g:

stage/sql/Copying to tmp table
stage/innodb/alter table (end)
stage/innodb/alter table (flush)
stage/innodb/alter table (insert)
stage/innodb/alter table (log apply index)
stage/innodb/alter table (log apply table)
stage/innodb/alter table (merge sort)
stage/innodb/alter table (read PK and internal sort)
stage/innodb/buffer pool load

For stage event schedule is not supported or enabled the required instruments or consumers, the corresponding column displays progress information to NULL.

 

More Reference

https://dev.mysql.com/doc/refman/5.7/en/sys-schema-progress-reporting.html

https://dev.mysql.com/doc/refman/5.7/en/sys-schema-prerequisites.html

https://dev.mysql.com/doc/refman/5.7/en/sys-schema-usage.html

Published 295 original articles · won praise 35 · views 80000 +

Guess you like

Origin blog.csdn.net/Hehuyi_In/article/details/105314757