please Help with MySQL optimization

please Help with MySQL optimization

by Gautam Saha -
Number of replies: 4

I am database novice.

I recently upgraded to version 1.8.

The following are red flags( the value parameters are in red) on my MYSQL database. I would be greatful if I could get some simple instructions or scripts to run on fixing these problems. Thanks in advance.

****************************************************************************************

Slow_queries 53 k The number of queries that have taken more than long_query_time seconds. MySQL - Documentation

Handler_read_rnd 1,229 M 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 4,043.72 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. 

Qcache_lowmem_prunes 35 M The number of queries that have been removed from the cache to free up memory for caching new queries. This information can help you tune the query cache size. The query cache uses a least recently used (LRU) strategy to decide which queries to remove from the cache. 

Created_tmp_disk_tables 1,339 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 1,081 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. 

Select_range_check 3,738  The number of joins without keys that check for key usage after each row. (If this is not 0, you should carefully check the indexes of your tables.) 

Sort_merge_passes 748  The number of merge passes the sort algorithm has had to do. If this value is large, you should consider increasing the value of the sort_buffer_size system variable. 

Opened_tables 6,595 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 60 M 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. 

Average of ratings: -
In reply to Gautam Saha

Re: please Help with MySQL optimization

by Ken Wilson -
Hi Gautam

Those are interesting statistics and it would be more helpful to us if you could please post the full output of the mysqladmin -u root -p ext var stat command as *an attachment*. We can then look at those variables, some of which are relative and some of which refer to index problems.

Thanks

Ken
In reply to Ken Wilson

Re: please Help with MySQL optimization

by Gautam Saha -

Hi Ken,

Thanks so much for your reply. You help a lot of people on this forum.

How exactly do I run this command?

When I ran,

mysqladmin -u root -p ext var stat

on the SQL query window I got a syntax error.

thanks in advance

In reply to Ken Wilson

Re: please Help with MySQL optimization

by Gautam Saha -

Dear Ken,

After reading some forums, it appears that people like me who have their moodle site hosted on a shared server with Siteground dont have much options to optimize or change parameters to optimize MYSQL. I dont have access to a conf file to make changes to MYSQL.

Also it appears that the SQL stats being reported are not statistics that are coming from my moodle site...it is being affected by other SQL queries that are happening on the shared hosting server.

You had posted a script called md-db-opt to optimize and repair the whole moodle database. Can this script be run safely? Should I give it a try and see if the bad numbers come down?

thanks again.

In reply to Gautam Saha

Re: please Help with MySQL optimization

by Ken Wilson -
OK - I understand why running on a shared host would produce those statistics. Maybe you could approach the Siteground helpdesk with these figures so that it can help them when reviewing the performance of that server? The mdl-db-opt script can be run in a production environment. It performs the mysql check, optimize and repair operations on each of the moodle tables.

It may, but probably may not, help - as it looks like the problems are related to server overloading and a lack of indexes in the database. http://moodle.org/mod/forum/discuss.php?d=58208 contains a summary at the end of missing indexes in some moodle tables - but this is for moodle 1.7, so (assuming moodle 1.8 has all those indexes) it again may not improve things.

Good luck!