Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Vorhergehende Überarbeitung | |||
— | content:mariadb_tuning [2022/12/25 22:32] (aktuell) – Daniel | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== MariaDB SQL- Tuning ====== | ||
+ | |||
+ | After setting up mariadb and tweaking its basic configuration, | ||
+ | |||
+ | It is not really well documented, how mariadb will output what exactly is the cause for bad performance. In phpMyAdmin there is a tab in the Server-Menu named Status where there is an Advisor, which may give hints for what may be wrong. But after that, there is no way to find the Statements, causing the trouble. Furtheron, many statements beeing problematik may not cause Errors or very slow behaviour, but are doing the "wrong things" | ||
+ | |||
+ | ===== Introducing the Slow Log ===== | ||
+ | |||
+ | For all those things, one can use the slow log - even if the name appears to only be useful for long running transcations. | ||
+ | |||
+ | There are three types of bad statement, that can be analysed with the slow log, each described in a seperate section. They cannot be analysed all in all without having big impact to the load of the server. | ||
+ | |||
+ | ==== Setup Logging ==== | ||
+ | |||
+ | Todos here: General logging - paths and setup logrotate | ||
+ | |||
+ | Keep in mind, that changes are lost each restart of mariadb if not set in configuration. | ||
+ | |||
+ | / | ||
+ | |||
+ | < | ||
+ | # This logname can be set in /etc/my.cnf | ||
+ | # by setting the variable " | ||
+ | # in the [mysqld] section as follows: | ||
+ | # | ||
+ | # [mysqld] | ||
+ | # log-error=/ | ||
+ | # | ||
+ | # If the root user has a password you have to create a | ||
+ | # / | ||
+ | # content: | ||
+ | # | ||
+ | # [mysqladmin] | ||
+ | # password = < | ||
+ | # user= root | ||
+ | # | ||
+ | # where "< | ||
+ | # | ||
+ | # ATTENTION: This / | ||
+ | # for root ! | ||
+ | / | ||
+ | # create 600 mysql mysql | ||
+ | su mysql mysql | ||
+ | notifempty | ||
+ | daily | ||
+ | rotate 3 | ||
+ | missingok | ||
+ | compress | ||
+ | postrotate | ||
+ | # just if mariadbd is really running | ||
+ | if test -x / | ||
+ | / | ||
+ | then | ||
+ | / | ||
+ | flush-engine-log flush-general-log flush-slow-log | ||
+ | ret=$? | ||
+ | if test $ret -ne 0 | ||
+ | then | ||
+ | echo "/ | ||
+ | echo "the root acount is protected by password.">& | ||
+ | echo "See comments in / | ||
+ | exit $ret | ||
+ | fi | ||
+ | fi | ||
+ | endscript | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | === Method 1: Slow Queries === | ||
+ | |||
+ | This is ordinary. TODO: Explain long_query value… | ||
+ | |||
+ | === Method 2: Queries causing Disk- Access === | ||
+ | |||
+ | This is the real fun. There may be queries, that are executed fast, but are causing temporary files written to disk each execution. The programmer itself has no influence to this behaviour, as mariadb is doing it internally. | ||
+ | |||
+ | In the Advicsor you can find: "Many temporary tables are being written to disk instead of being kept in memory." | ||
+ | |||
+ | Analyse it with those settings in / | ||
+ | |||
+ | < | ||
+ | log-slow-verbosity=explain | ||
+ | log-slow-disabled_statements=admin | ||
+ | log-slow-admin-statements=off | ||
+ | long-query-time=0 | ||
+ | log-slow-filter=filesort_on_disk, | ||
+ | |||
+ | </ | ||
+ | |||
+ | As you can see, there is a trick: by setting long-query-time to 0, every statement will be logged AND explained. Be cautious to alway apply a filter to that logging, as otherwise ALL statements would be analysed. | ||
+ | |||
+ | === Method 3: Queries having no index === | ||
+ | |||
+ | For troubleshooting queries without an index, you can also use: | ||
+ | |||
+ | < | ||
+ | log-slow-verbosity=explain | ||
+ | log-slow-disabled_statements=admin | ||
+ | log-slow-admin-statements=off | ||
+ | long-query-time=1000 | ||
+ | log-slow-filter=not_using_index | ||
+ | |||
+ | </ | ||
+ | |||
+ | Todo: explain more | ||
+ | |||