**Hi. I need help/advice on tuning my mysql database. Moodles been running fine for a year or so, but I think its finally catching up to itself and needs tuning. Its been sporadically locking up. And Im not a DBA by any means. So any advice is appreciated.
**I've done two things to gather info... First, installed the moodle database plugin. I then went to the page, clicked on "Show mySql runtime information", and found the entries in RED. Here I'll list the RED entries... which I assume need attention....
Innodb_buffer_pool_reads 12 The number of logical reads that InnoDB could not satisfy from buffer pool and had to do a single-page read.
Handler_read_rnd 716 k The number of requests to read a row based on a fixed position. This is high if you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan whole tables or you have joins that don't use keys properly.
Handler_read_rnd_next 65 M The number of requests to read the next row in the data file. This is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.
Created_tmp_disk_tables 20 k The number of temporary tables on disk created automatically by the server while executing statements. If Created_tmp_disk_tables is big, you may want to increase the tmp_table_size value to cause temporary tables to be memory-based instead of disk-based.
Select_full_join 22 k The number of joins that do not use indexes. If this value is not 0, you should carefully check the indexes of your tables.
Opened_tables 17 k The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.
Table_locks_waited 12 The number of times that a table lock could not be acquired immediately and a wait was needed. If this is high, and you have performance problems, you should first optimize your queries, and then either split your table or tables or use replication.
**Also, on the server itself from the command line, I ran Mysqltuner which gave me a nice report, it's findings are...
-------- Recommendations -----------------------------------------------------
General recommendations:
Add skip-innodb to MySQL configuration to disable InnoDB
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
Adjust your join queries to always utilize indexes
Set thread_cache_size to 4 as a starting value
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
query_cache_size (>= 8M)
join_buffer_size (> 128.0K, or always use indexes with joins)
thread_cache_size (start at 4)
table_cache (> 64)
Firstly, how do adjust the variables above?? (the table_cache size, the query_cache_size, etc..)??
How can I "optimize tables" in a single command or click?
How can I "reindex" the database, I think that needs done.
Any other suggestions are welcome! Thanks!
I don't know much about MySQL either, but have you seen Performance#MySQL_performance?
At a quick glance there's nothing too frightening here. Are you *sure* that MySQL is your bottleneck? I say this because it usually isn't. I would suspect Apache processes burning up your memory first every time.
How can I check into Apache being the culprit? And/or tweak apache?
Thanks for the advice, I'm thinking maybe it is Apache. I read the moodle performance page for suggestions about apache. The first thing I'm trying to tweek is the MaxClients variable - but I'm having issues...
Here is the section from my server-tuning.conf file that I modified..
# prefork MPM
<IfModule prefork.c>
# number of server processes to start
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#startservers
StartServers 5
# minimum number of server processes which are kept spare
# http://httpd.apache.org/docs/2.2/mod/prefork.html#minspareservers
MinSpareServers 5
# maximum number of server processes which are kept spare
# http://httpd.apache.org/docs/2.2/mod/prefork.html#maxspareservers
MaxSpareServers 10
# highest possible MaxClients setting for the lifetime of the Apache process.
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#serverlimit
#ServerLimit 150
ServerLimit 300
# maximum number of server processes allowed to start
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients
#MaxClients 150
MaxClients 300
# maximum number of requests a server process serves
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxrequestsperchild
MaxRequestsPerChild 10000
</IfModule>
However, when I restart apace, I notice an error in the error log that states the following...
[Mon Feb 02 09:15:01 2009] [notice] Graceful restart requested, doing restart
WARNING: MaxClients of 300 exceeds ServerLimit value of 150 servers,
lowering MaxClients to 150. To increase, please see the ServerLimit
directive.
[Mon Feb 02 09:15:01 2009] [warn] WARNING: Attempt to change ServerLimit ignored during restart
[Mon Feb 02 09:15:01 2009] [notice] Apache/2.2.3 (Linux/SUSE) configured -- resuming normal operations
Am I missing something here? I have both limits set at 300 but upon restarting apache, it doesn't think so...
Here is the section from my server-tuning.conf file that I modified..
# prefork MPM
<IfModule prefork.c>
# number of server processes to start
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#startservers
StartServers 5
# minimum number of server processes which are kept spare
# http://httpd.apache.org/docs/2.2/mod/prefork.html#minspareservers
MinSpareServers 5
# maximum number of server processes which are kept spare
# http://httpd.apache.org/docs/2.2/mod/prefork.html#maxspareservers
MaxSpareServers 10
# highest possible MaxClients setting for the lifetime of the Apache process.
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#serverlimit
#ServerLimit 150
ServerLimit 300
# maximum number of server processes allowed to start
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients
#MaxClients 150
MaxClients 300
# maximum number of requests a server process serves
# http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxrequestsperchild
MaxRequestsPerChild 10000
</IfModule>
However, when I restart apace, I notice an error in the error log that states the following...
[Mon Feb 02 09:15:01 2009] [notice] Graceful restart requested, doing restart
WARNING: MaxClients of 300 exceeds ServerLimit value of 150 servers,
lowering MaxClients to 150. To increase, please see the ServerLimit
directive.
[Mon Feb 02 09:15:01 2009] [warn] WARNING: Attempt to change ServerLimit ignored during restart
[Mon Feb 02 09:15:01 2009] [notice] Apache/2.2.3 (Linux/SUSE) configured -- resuming normal operations
Am I missing something here? I have both limits set at 300 but upon restarting apache, it doesn't think so...
Think maybe I got it. Previously, I was doing a restart (either by 'apachectl -k restart' or 'apachectl -k graceful') and getting the error...
But when I did an actual '-k stop' and '-k start', I don't seem to get the error now.
This sound right? Think I can assume the new MaxClients and ServerLimit values are being used?
But when I did an actual '-k stop' and '-k start', I don't seem to get the error now.
This sound right? Think I can assume the new MaxClients and ServerLimit values are being used?
Greetings,
If you're still having database problems here are some general tips for myisam:
Run a table check while mysql is shutdown:
If you're still having database problems here are some general tips for myisam:
Run a table check while mysql is shutdown:
myisamchk -e /usr/local/mysql/data/moodledatabase/*.MYI
That will tell you if there is a problem with a table if so repair it using:
myisamchk -r /tablename.MYI
(http://dev.mysql.com/doc/refman/5.0/en/crash-recovery.html)
To optimize a table it is simple to do from a mysql prompt:
optimize mdl_log;
This can be an intensive time taking process.
http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html
Depending on how your database is being used there are a lot of variables in the my.cnf you can tweak to optimize system performance.
I'd look first at your query_cache_size and make sure it is set high. (you can tell by if your query cache hit ratio is less than about 60%)
I'd also increase the table cache to the number of moodle tables your site actively uses. In my case we set it at something like 64 before switching table engines.
You can also look at your sort_buffer which is used when ordering results which moodle asks for often.
For further diagnostic purposes, I'd recommend turning on the slow query log which can be done by adding this line to my.cnf:
log_slow_queries=/var/log/mysql/mysql-slow.log
(just make sure that directory exists and your mysql daemon can write to it.)
You can then use mysqldumpslow to get a read out of any queries that are affecting your performance which will also point you to areas to optimize.
Finally I'll suggest a consideration of switching to INNODB. INNODB is a more robust engine for SQL. It is ACID compliant (http://en.wikipedia.org/wiki/ACID) and much easier to configure. All you really need to do is throw all your memory at the innodb_buffer_pool. The downside is that it has a bit higher overhead because of its transactional nature, but its ease of tuning and lack of corruption often make it a better choice.