1. 程式人生 > >Percona Toolkit使用之pt-variable-advisor

Percona Toolkit使用之pt-variable-advisor

     pt-variable-advisor的功能是分析MySQL系統變數配置然後對潛在問題提出建議。

     用法如下:

pt-variable-advisor [OPTIONS] [DSN]

     pt-variable-advisor分析系統變數配置然後對潛在問題提出建議。

     ①從localhost獲取SHOW VARIABLES。

pt-variable-advisor localhost

     ②從保存於vars.txt的檔案中獲取SHOW VARIABLES輸出。

pt-variable-advisor --source-of-variables vars.txt

     pt-variable-advisor檢測“ SHOW VARIABLES ”來查詢不好的變數值和設定,判斷標準基於若干規則。它會報告匹配到這些規則的變數,因此你可以在自己的MySQL伺服器上找到差的配置。

     截止當前的版本,pt-variable-advisor只檢測“ SHOW VARIABLES ”,但是其他的輸入源,例如“ SHOW STATUS ”和“ SHOW SLAVE STATUS ”,正在計劃中。

     有一些pt-variable-advisor用於SHOW VARIABLES檢測的規則。每個規則包含三個部分:ID、嚴重性和描述。

     規則ID是該規則的一個簡短的唯一命名。它通常與該規則檢測的變數相關。如果變數被若干個規則檢測,那麼規則ID將被編號,例如“-1”、“-2”、“-N”。

     規則嚴重性表明該規則與查詢匹配的重要性。我們使用NOTE、WARN和CRIT來表示其程度。

     規則描述是一個文字的、人類可讀的、當變數匹配該規則時意味著什麼的說明。根據生成的報告的冗餘程度,你將在描述中看到更多的文字。預設情況下,你只會看到首句,這可以說是規則含義的簡述。在更高級別的冗餘度下,你將看到附加語句。

     以下為個人本地環境的測試資料。

     首先是簡單檢測。

[email protected]:~# pt-variable-advisor h=192.168.112.129, P=3306, u=root, p=123456
# WARN delay_key_write: MyISAM index blocks are never flushed until necessary.

# WARN key_buffer_size: The key buffer size is set to its default value, which is not good  for most production systems.

# NOTE sort_buffer_size-1: The sort_buffer_size variable should generally be left at its default unless an expert determines it is nece
ssary to change it.
# WARN expire_logs_days: Binary logs are enabled, but automatic purging is not enabled.

# NOTE innodb_data_file_path: Auto-extending InnoDB files can consume a lot of disk space that is very difficult to reclaim later.

# NOTE innodb_flush_method: Most production database servers that use InnoDB should set innodb_flush_method to O_DIRECT to avoid double
-buffering, unless the I/O system is very low performance.
# WARN myisam_recover_options: myisam_recover_options should be set to some value such as BACKUP,FORCE to ensure that table corruption 
is noticed.

     檢視具體的解釋資訊(--verbose)。

[email protected]:~# pt-variable-advisor h=192.168.112.129, P=3306, u=root, p=123456 --verbose --verbose
# WARN delay_key_write: MyISAM index blocks are never flushed until necessary.  If there is a server crash, data corruption on MyISAM t
ables can be much worse than usual.
# WARN key_buffer_size: The key buffer size is set to its default value, which is not good  for most production systems.  In a producti
on environment, key_buffer_size should be larger than the default 8MB size.
# NOTE sort_buffer_size-1: The sort_buffer_size variable should generally be left at its default unless an expert determines it is nece
ssary to change it.
# WARN expire_logs_days: Binary logs are enabled, but automatic purging is not enabled.  If you do not purge binary logs, your disk wil
l fill up.  If you delete binary logs externally to MySQL, you will cause unwanted behaviors. Always ask MySQL to purge obsolete logs, never delete them externally.
# NOTE innodb_data_file_path: Auto-extending InnoDB files can consume a lot of disk space that is very difficult to reclaim later.  Som
e people prefer to set innodb_file_per_table and allocate a fixed-size file for ibdata1.
# NOTE innodb_flush_method: Most production database servers that use InnoDB should set innodb_flush_method to O_DIRECT to avoid double
-buffering, unless the I/O system is very low performance.
# WARN myisam_recover_options: myisam_recover_options should be set to some value such as BACKUP,FORCE to ensure that table corruption 
is noticed.

     參考: