Loading...
MySQL 9.5 Reference Manual 9.5의 29.1 Performance Schema Quick Start의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
이 섹션에서는 Performance Schema를 간단히 소개하고, 그것을 어떻게 사용하는지 보여 주는 예제를 제시합니다. 추가 예제는 Section 29.19, “Using the Performance Schema to Diagnose Problems”를 참조하십시오.
Performance Schema는 기본적으로 활성화되어 있습니다. 이를 명시적으로 활성화하거나 비활성화하려면, 서버를 시작할 때 performance_schema 변수를 적절한 값으로 설정하십시오. 예를 들어, 서버 my.cnf 파일에 다음과 같이 설정합니다:
1[mysqld] 2performance_schema=ON
서버가 시작될 때, 서버는 performance_schema를 확인하고 Performance Schema를 초기화하려고 시도합니다. 초기화가 성공했는지 확인하려면 다음 문을 사용합니다:
1mysql> SHOW VARIABLES LIKE 'performance_schema'; 2+--------------------+-------+ 3| Variable_name | Value | 4+--------------------+-------+ 5| performance_schema | ON | 6+--------------------+-------+
값이 ON이면 Performance Schema가 성공적으로 초기화되었으며 사용할 준비가 되었음을 의미합니다. 값이 OFF이면 어떤 오류가 발생했음을 의미합니다. 무엇이 잘못되었는지에 대한 정보는 서버 에러 로그를 확인하십시오.
Performance Schema는 스토리지 엔진으로 구현되므로, Information Schema ENGINES 테이블이나 SHOW ENGINES 문 출력에서 이를 확인할 수 있습니다:
1mysql> SELECT * FROM INFORMATION_SCHEMA.ENGINES 2 WHERE ENGINE='PERFORMANCE_SCHEMA'\G 3*************************** 1. row *************************** 4 ENGINE: PERFORMANCE_SCHEMA 5 SUPPORT: YES 6 COMMENT: Performance Schema 7TRANSACTIONS: NO 8 XA: NO 9 SAVEPOINTS: NO 10 11mysql> SHOW ENGINES\G 12... 13 Engine: PERFORMANCE_SCHEMA 14 Support: YES 15 Comment: Performance Schema 16Transactions: NO 17 XA: NO 18 Savepoints: NO 19...
PERFORMANCE_SCHEMA 스토리지 엔진은 performance_schema 데이터베이스의 테이블을 조작합니다. performance_schema를 기본 데이터베이스로 설정하면 테이블을 참조할 때 데이터베이스 이름으로 수식할 필요가 없습니다:
1mysql> USE performance_schema;
Performance Schema 테이블은 performance_schema 데이터베이스에 저장됩니다. 이 데이터베이스와 그 테이블 구조에 대한 정보는 다른 데이터베이스와 마찬가지로 INFORMATION_SCHEMA 데이터베이스에서 셀렉트 하거나 SHOW 문을 사용하여 얻을 수 있습니다. 예를 들어, 다음 문 중 하나를 사용하여 어떤 Performance Schema 테이블이 존재하는지 확인할 수 있습니다:
1mysql> SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES 2 WHERE TABLE_SCHEMA = 'performance_schema'; 3+------------------------------------------------------+ 4| TABLE_NAME | 5+------------------------------------------------------+ 6| accounts | 7| cond_instances | 8... 9| events_stages_current | 10| events_stages_history | 11| events_stages_history_long | 12| events_stages_summary_by_account_by_event_name | 13| events_stages_summary_by_host_by_event_name | 14| events_stages_summary_by_thread_by_event_name | 15| events_stages_summary_by_user_by_event_name | 16| events_stages_summary_global_by_event_name | 17| events_statements_current | 18| events_statements_history | 19| events_statements_history_long | 20... 21| file_instances | 22| file_summary_by_event_name | 23| file_summary_by_instance | 24| host_cache | 25| hosts | 26| memory_summary_by_account_by_event_name | 27| memory_summary_by_host_by_event_name | 28| memory_summary_by_thread_by_event_name | 29| memory_summary_by_user_by_event_name | 30| memory_summary_global_by_event_name | 31| metadata_locks | 32| mutex_instances | 33| objects_summary_global_by_type | 34| performance_timers | 35| replication_connection_configuration | 36| replication_connection_status | 37| replication_applier_configuration | 38| replication_applier_status | 39| replication_applier_status_by_coordinator | 40| replication_applier_status_by_worker | 41| rwlock_instances | 42| session_account_connect_attrs | 43| session_connect_attrs | 44| setup_actors | 45| setup_consumers | 46| setup_instruments | 47| setup_objects | 48| socket_instances | 49| socket_summary_by_event_name | 50| socket_summary_by_instance | 51| table_handles | 52| table_io_waits_summary_by_index_usage | 53| table_io_waits_summary_by_table | 54| table_lock_waits_summary_by_table | 55| threads | 56| users | 57+------------------------------------------------------+ 58 59mysql> SHOW TABLES FROM performance_schema; 60+------------------------------------------------------+ 61| Tables_in_performance_schema | 62+------------------------------------------------------+ 63| accounts | 64| cond_instances | 65| events_stages_current | 66| events_stages_history | 67| events_stages_history_long | 68...
Performance Schema 테이블의 수는 추가 인스트루먼테이션 구현이 진행됨에 따라 시간이 지남에 따라 증가합니다.
performance_schema 데이터베이스의 이름은 소문자이며, 그 안의 테이블 이름도 모두 소문자입니다. 쿼리에서는 이름을 소문자로 지정해야 합니다.
개별 테이블의 구조를 보려면 SHOW CREATE TABLE을 사용하십시오:
1mysql> SHOW CREATE TABLE performance_schema.setup_consumers\G 2*************************** 1. row *************************** 3 Table: setup_consumers 4Create Table: CREATE TABLE `setup_consumers` ( 5 `NAME` varchar(64) NOT NULL, 6 `ENABLED` enum('YES','NO') NOT NULL, 7 PRIMARY KEY (`NAME`) 8) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
테이블 구조는 INFORMATION_SCHEMA.COLUMNS 같은 테이블에서 셀렉트 하거나 SHOW COLUMNS 같은 문을 사용해서도 확인할 수 있습니다.
performance_schema 데이터베이스의 테이블은 그 안에 들어 있는 정보의 유형에 따라 그룹화할 수 있습니다: 현재 이벤트, 이벤트 히스토리 및 요약, 오브젝트 인스턴스, 그리고 설정(구성) 정보입니다. 다음 예제들은 이러한 테이블의 몇 가지 사용 방법을 보여 줍니다. 각 그룹의 테이블에 대한 자세한 정보는 Section 29.12, “Performance Schema Table Descriptions”를 참조하십시오.
초기 상태에서는 모든 인스트루먼트와 컨슈머가 활성화되어 있지 않으므로, Performance Schema는 모든 이벤트를 수집하지 않습니다. 이들을 모두 켜고 이벤트 타이밍을 활성화하려면 두 개의 문을 실행합니다 (로우 수는 MySQL 버전에 따라 달라질 수 있습니다):
1mysql> UPDATE performance_schema.setup_instruments 2 SET ENABLED = 'YES', TIMED = 'YES'; 3Query OK, 560 rows affected (0.04 sec) 4mysql> UPDATE performance_schema.setup_consumers 5 SET ENABLED = 'YES'; 6Query OK, 10 rows affected (0.00 sec)
서버가 현재 무엇을 하고 있는지 보려면 events_waits_current 테이블을 검사하십시오. 이 테이블에는 각 스레드에 대해, 해당 스레드의 가장 최근에 모니터된 이벤트를 한 로우로 보여 줍니다:
1mysql> SELECT * 2 FROM performance_schema.events_waits_current\G 3*************************** 1. row *************************** 4 THREAD_ID: 0 5 EVENT_ID: 5523 6 END_EVENT_ID: 5523 7 EVENT_NAME: wait/synch/mutex/mysys/THR_LOCK::mutex 8 SOURCE: thr_lock.c:525 9 TIMER_START: 201660494489586 10 TIMER_END: 201660494576112 11 TIMER_WAIT: 86526 12 SPINS: NULL 13 OBJECT_SCHEMA: NULL 14 OBJECT_NAME: NULL 15 INDEX_NAME: NULL 16 OBJECT_TYPE: NULL 17OBJECT_INSTANCE_BEGIN: 142270668 18 NESTING_EVENT_ID: NULL 19 NESTING_EVENT_TYPE: NULL 20 OPERATION: lock 21 NUMBER_OF_BYTES: NULL 22 FLAGS: 0 23...
이 이벤트는 스레드 0이 THR_LOCK::mutex라는, mysys 서브시스템의 뮤텍스에 대해 락을 획득하기 위해 86,526 피코초 동안 대기하고 있었음을 나타냅니다. 처음 몇 개의 컬럼은 다음 정보를 제공합니다:
ID 컬럼은 어떤 스레드에서 이벤트가 발생했는지와 이벤트 번호를 나타냅니다.
EVENT_NAME은 어떤 것이 인스트루먼트되었는지를 나타내고, SOURCE는 인스트루먼트된 코드가 들어 있는 소스 파일을 나타냅니다.
타이머 컬럼은 이벤트가 언제 시작되고 언제 종료되었는지, 그리고 얼마나 오래 걸렸는지를 보여 줍니다. 이벤트가 아직 진행 중인 경우 TIMER_END 및 TIMER_WAIT 값은 NULL입니다. 타이머 값은 근사치이며 피코초 단위로 표현됩니다. 타이머 및 이벤트 시간 수집에 대한 정보는 Section 29.4.1, “Performance Schema Event Timing”을 참조하십시오.
히스토리 테이블에는 현재-이벤트 테이블과 동일한 유형의 로우가 들어 있지만, 더 많은 로우를 가지고 있으며 서버가 “현재”가 아니라 “최근에” 무엇을 했는지를 보여 줍니다. events_waits_history 및 events_waits_history_long 테이블에는 각각 스레드당 가장 최근 10개 이벤트와 가장 최근 10,000개 이벤트가 들어 있습니다. 예를 들어, 스레드 13이 생성한 최근 이벤트에 대한 정보를 보려면 다음과 같이 합니다:
1mysql> SELECT EVENT_ID, EVENT_NAME, TIMER_WAIT 2 FROM performance_schema.events_waits_history 3 WHERE THREAD_ID = 13 4 ORDER BY EVENT_ID; 5+----------+-----------------------------------------+------------+ 6| EVENT_ID | EVENT_NAME | TIMER_WAIT | 7+----------+-----------------------------------------+------------+ 8| 86 | wait/synch/mutex/mysys/THR_LOCK::mutex | 686322 | 9| 87 | wait/synch/mutex/mysys/THR_LOCK_malloc | 320535 | 10| 88 | wait/synch/mutex/mysys/THR_LOCK_malloc | 339390 | 11| 89 | wait/synch/mutex/mysys/THR_LOCK_malloc | 377100 | 12| 90 | wait/synch/mutex/sql/LOCK_plugin | 614673 | 13| 91 | wait/synch/mutex/sql/LOCK_open | 659925 | 14| 92 | wait/synch/mutex/sql/THD::LOCK_thd_data | 494001 | 15| 93 | wait/synch/mutex/mysys/THR_LOCK_malloc | 222489 | 16| 94 | wait/synch/mutex/mysys/THR_LOCK_malloc | 214947 | 17| 95 | wait/synch/mutex/mysys/LOCK_alarm | 312993 | 18+----------+-----------------------------------------+------------+
새 이벤트가 히스토리 테이블에 추가되면, 테이블이 가득 찬 경우 오래된 이벤트는 버려집니다.
요약 테이블은 시간에 따른 모든 이벤트에 대한 집계 정보를 제공합니다. 이 그룹의 테이블은 이벤트 데이터를 서로 다른 방식으로 요약합니다. 어떤 인스트루먼트가 가장 많이 실행되었는지 또는 가장 많은 대기 시간을 사용했는지 확인하려면, events_waits_summary_global_by_event_name 테이블을 COUNT_STAR 또는 SUM_TIMER_WAIT 컬럼으로 정렬하십시오. 각각은 모든 이벤트에 대해 계산된 COUNT(*) 또는 SUM(TIMER_WAIT) 값에 해당합니다:
1mysql> SELECT EVENT_NAME, COUNT_STAR 2 FROM performance_schema.events_waits_summary_global_by_event_name 3 ORDER BY COUNT_STAR DESC LIMIT 10; 4+---------------------------------------------------+------------+ 5| EVENT_NAME | COUNT_STAR | 6+---------------------------------------------------+------------+ 7| wait/synch/mutex/mysys/THR_LOCK_malloc | 6419 | 8| wait/io/file/sql/FRM | 452 | 9| wait/synch/mutex/sql/LOCK_plugin | 337 | 10| wait/synch/mutex/mysys/THR_LOCK_open | 187 | 11| wait/synch/mutex/mysys/LOCK_alarm | 147 | 12| wait/synch/mutex/sql/THD::LOCK_thd_data | 115 | 13| wait/io/file/myisam/kfile | 102 | 14| wait/synch/mutex/sql/LOCK_global_system_variables | 89 | 15| wait/synch/mutex/mysys/THR_LOCK::mutex | 89 | 16| wait/synch/mutex/sql/LOCK_open | 88 | 17+---------------------------------------------------+------------+ 18 19mysql> SELECT EVENT_NAME, SUM_TIMER_WAIT 20 FROM performance_schema.events_waits_summary_global_by_event_name 21 ORDER BY SUM_TIMER_WAIT DESC LIMIT 10; 22+----------------------------------------+----------------+ 23| EVENT_NAME | SUM_TIMER_WAIT | 24+----------------------------------------+----------------+ 25| wait/io/file/sql/MYSQL_LOG | 1599816582 | 26| wait/synch/mutex/mysys/THR_LOCK_malloc | 1530083250 | 27| wait/io/file/sql/binlog_index | 1385291934 | 28| wait/io/file/sql/FRM | 1292823243 | 29| wait/io/file/myisam/kfile | 411193611 | 30| wait/io/file/myisam/dfile | 322401645 | 31| wait/synch/mutex/mysys/LOCK_alarm | 145126935 | 32| wait/io/file/sql/casetest | 104324715 | 33| wait/synch/mutex/sql/LOCK_plugin | 86027823 | 34| wait/io/file/sql/pid | 72591750 | 35+----------------------------------------+----------------+
이 결과는 THR_LOCK_malloc 뮤텍스가 사용 빈도와 스레드가 그것을 획득하려고 대기하는 시간량 측면 모두에서 “hot”하다는 것을 보여 줍니다.
참고
THR_LOCK_malloc 뮤텍스는 디버그 빌드에서만 사용됩니다. 프로덕션 빌드에서는 존재하지 않으므로 hot하지 않습니다.
인스턴스 테이블은 어떤 유형의 오브젝트가 인스트루먼트되었는지를 문서화합니다. 인스트루먼트된 오브젝트는 서버에서 사용될 때 이벤트를 생성합니다. 이 테이블들은 이벤트 이름과 설명 노트 또는 상태 정보를 제공합니다. 예를 들어, file_instances 테이블은 파일 I/O 오퍼레이션에 대한 인스트루먼트 인스턴스와 관련된 파일을 나열합니다:
1mysql> SELECT * 2 FROM performance_schema.file_instances\G 3*************************** 1. row *************************** 4 FILE_NAME: /opt/mysql-log/60500/binlog.000007 5EVENT_NAME: wait/io/file/sql/binlog 6OPEN_COUNT: 0 7*************************** 2. row *************************** 8 FILE_NAME: /opt/mysql/60500/data/mysql/tables_priv.MYI 9EVENT_NAME: wait/io/file/myisam/kfile 10OPEN_COUNT: 1 11*************************** 3. row *************************** 12 FILE_NAME: /opt/mysql/60500/data/mysql/columns_priv.MYI 13EVENT_NAME: wait/io/file/myisam/kfile 14OPEN_COUNT: 1 15...
설정 테이블은 모니터링 특성을 구성하고 표시하는 데 사용됩니다. 예를 들어, setup_instruments는 이벤트를 수집할 수 있는 인스트루먼트 집합을 나열하고, 그 중 어떤 것이 활성화되어 있는지를 보여 줍니다:
1mysql> SELECT NAME, ENABLED, TIMED 2 FROM performance_schema.setup_instruments; 3+---------------------------------------------------+---------+-------+ 4| NAME | ENABLED | TIMED | 5+---------------------------------------------------+---------+-------+ 6... 7| stage/sql/end | NO | NO | 8| stage/sql/executing | NO | NO | 9| stage/sql/init | NO | NO | 10| stage/sql/insert | NO | NO | 11... 12| statement/sql/load | YES | YES | 13| statement/sql/grant | YES | YES | 14| statement/sql/check | YES | YES | 15| statement/sql/flush | YES | YES | 16... 17| wait/synch/mutex/sql/LOCK_global_read_lock | YES | YES | 18| wait/synch/mutex/sql/LOCK_global_system_variables | YES | YES | 19| wait/synch/mutex/sql/LOCK_lock_db | YES | YES | 20| wait/synch/mutex/sql/LOCK_manager | YES | YES | 21... 22| wait/synch/rwlock/sql/LOCK_grant | YES | YES | 23| wait/synch/rwlock/sql/LOGGER::LOCK_logger | YES | YES | 24| wait/synch/rwlock/sql/LOCK_sys_init_connect | YES | YES | 25| wait/synch/rwlock/sql/LOCK_sys_init_slave | YES | YES | 26... 27| wait/io/file/sql/binlog | YES | YES | 28| wait/io/file/sql/binlog_index | YES | YES | 29| wait/io/file/sql/casetest | YES | YES | 30| wait/io/file/sql/dbopt | YES | YES | 31...
인스트루먼트 이름을 해석하는 방법을 이해하려면 Section 29.6, “Performance Schema Instrument Naming Conventions”을 참조하십시오.
인스트루먼트에 대해 이벤트를 수집할지 여부를 제어하려면, 해당 인스트루먼트의 ENABLED 값을 YES 또는 NO로 설정합니다. 예:
1mysql> UPDATE performance_schema.setup_instruments 2 SET ENABLED = 'NO' 3 WHERE NAME = 'wait/synch/mutex/sql/LOCK_mysql_create_db';
Performance Schema는 수집된 이벤트를 사용하여 performance_schema 데이터베이스의 테이블을 갱신하며, 이 테이블들은 이벤트 정보의 “컨슈머” 역할을 합니다. setup_consumers 테이블은 사용 가능한 컨슈머와 활성화 여부를 나열합니다:
1mysql> SELECT * FROM performance_schema.setup_consumers; 2+----------------------------------+---------+ 3| NAME | ENABLED | 4+----------------------------------+---------+ 5| events_stages_current | NO | 6| events_stages_history | NO | 7| events_stages_history_long | NO | 8| events_statements_cpu | NO | 9| events_statements_current | YES | 10| events_statements_history | YES | 11| events_statements_history_long | NO | 12| events_transactions_current | YES | 13| events_transactions_history | YES | 14| events_transactions_history_long | NO | 15| events_waits_current | NO | 16| events_waits_history | NO | 17| events_waits_history_long | NO | 18| global_instrumentation | YES | 19| thread_instrumentation | YES | 20| statements_digest | YES | 21+----------------------------------+---------+
Performance Schema가 특정 컨슈머를 이벤트 정보의 목적지로 유지할지 여부를 제어하려면, 해당 컨슈머의 ENABLED 값을 설정하십시오.
설정 테이블과 이들을 사용하여 이벤트 수집을 제어하는 방법에 대한 자세한 정보는 Section 29.4.2, “Performance Schema Event Filtering”를 참조하십시오.
이전 그룹들 어느 쪽에도 속하지 않는 기타 테이블도 일부 있습니다. 예를 들어, performance_timers 테이블은 사용 가능한 이벤트 타이머와 그 특성을 나열합니다. 타이머에 대한 정보는 Section 29.4.1, “Performance Schema Event Timing”을 참조하십시오.
29 MySQL Performance Schema
29.2 Performance Schema Build Configuration