Author Topic: tunning wordpress wp_options autoload lock database and slow query  (Read 3564 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
tunning wordpress wp_options autoload lock database and slow query
« on: มีนาคม 02, 2015, 10:22:29 PM »
วันนี้ เจอ slow_query เทพเข้ามาครับ เนื่องจากลูกค้าใช้งาน wordpress แล้ว content ในเว็บเยอะมากๆ
ทำให้ table lock แล้วดึง load ขึ้น เชคไปเจอ select ตัว wp_option ของ wordpress ครับ

mysql> show full processlist;
+-----+-------------+-----------+---------------------+---------+------+--------------+-------------------------------------------------------------------------------------------------------------------------------+
| Id  | User        | Host      | db                  | Command | Time | State        | Info                                                                                                                          |
+-----+-------------+-----------+---------------------+---------+------+--------------+-------------------------------------------------------------------------------------------------------------------------------+
| 488 | blog  | localhost | blog | Query   |  240 | Sending data | SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'

#แรกเริ่มทำการเชค query เพื่อเชคข้อมูลก่อน
mysql>use blog;
mysql>SELECT COUNT(*), autoload FROM wp_options GROUP BY autoload;
if a large majority of them are set to 'no', you can solve the problem for now by adding an index on autoload.

จัดการทำ index ให้กับ table นี้ซะ
#ALTER TABLE wp_options ADD INDEX (`autoload`);
However, you might want to get to the bottom of why that table has gotten too large. Possibly some badly written plugin doing something fishy.

ลองดูนะครับผม : )