• Over the past couple months I’ve been having some strange issues with very long database queries which end up crashing the db and turning up the “error: unable to connect to database” message. Rebooting the db container I’m on (Mediatemple is my host) usually clears it up. Any help or ideas would be greatly appreciated.

    The site is https://blog.iso50.com

    Here is the db log of queries taking over 1 second which was created right after one such crash:

    Created 10:00 PM 08/13/2009
    ### 427 Queries
    ### Total time: 34357.839755, Average time: 80.4633249531616
    ### Taking 5.289689 to 203.258867 seconds to complete
    ### Rows analyzed 0 - 312
    SET timestamp=XXX;
    SELECT option_name, option_value FROM wp_options WHERE autoload = 'XXX';
    
    SET timestamp=1250225980;
    SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes';
    
    ### 281 Queries
    ### Total time: 22646.863787, Average time: 80.5938213060498
    ### Taking 5.212969 to 243.049226 seconds to complete
    ### Rows analyzed 0 - 312
    # User@Host: dbXXX[dbXXX] @ [XXX.XXX.XXX.XXX]
    
    # User@Host: db26001[db26001] @ [70.32.68.20]
    
    ### 152 Queries
    ### Total time: 13694.990108, Average time: 90.098619131579
    ### Taking 5.212969 to 243.049226 seconds to complete
    ### Rows analyzed 68 - 312
    SET timestamp=XXX;
    SELECT option_name, option_value FROM wp_options;
    
    SET timestamp=1250225990;
    SELECT option_name, option_value FROM wp_options;
    
    ### 17 Queries
    ### Total time: 1020.516299, Average time: 60.0303705294118
    ### Taking 16.693573 to 124.666902 seconds to complete
    ### Rows analyzed 0 - 0
    SET timestamp=XXX;
    UPDATE <code>wp_options</code> SET <code>option_value</code> = 'XXX' WHERE <code>option_name</code> = 'XXX';
    
    SET timestamp=1250224965;
    UPDATE <code>wp_options</code> SET <code>option_value</code> = '301766' WHERE <code>option_name</code> = 'akismet_spam_count';
    
    ### 4 Queries
    ### Total time: 351.330548, Average time: 87.832637
    ### Taking 54.716655 , 58.861937 , 116.705437 , 121.046519 seconds to complete
    ### Rows analyzed 0, 0, 0 and 0
    SET timestamp=XXX;
    INSERT INTO wp_fs_visits (ip, url, time_begin, time_last) VALUES ('XXX','XXX',XXX,XXX);
    
    SET timestamp=1250224965;
    INSERT INTO wp_fs_visits (ip, url, time_begin, time_last) VALUES ('67.175.246.73','/feed/',1250224844,1250224844);
    
    ### 3 Queries
    ### Total time: 269.326101, Average time: 89.775367
    ### Taking 74.740510 , 94.089207 , 100.496384 seconds to complete
    ### Rows analyzed 0, 0 and 0
    SET timestamp=XXX;
    DELETE FROM wp_options WHERE option_name = 'XXX';
    
    SET timestamp=1250225570;
    DELETE FROM wp_options WHERE option_name = '_transient_doing_cron';
    
    ### 2 Queries
    ### Total time: 133.638565, Average time: 66.8192825
    ### Taking 56.902287 , 76.736278 seconds to complete
    ### Rows analyzed 0 and 0
    SET timestamp=XXX;
    UPDATE wp_fs_visits SET time_last=XXX,url='XXX' WHERE ip='XXX' AND time_last > XXX;
    
    SET timestamp=1250225570;
    UPDATE wp_fs_visits SET time_last=1250225493,url='/feed/' WHERE ip='209.20.77.74' AND time_last > 1250221893;
    
    ### 1 Query
    ### Total time: 83.756655, Average time: 83.756655
    ### Taking 83.756655 seconds to complete
    ### Rows analyzed 0
    use dbXXX_wp;
    SET timestamp=XXX;
    SELECT option_name, option_value FROM wp_options WHERE autoload = 'XXX';
    
    use db26001_wp;
    SET timestamp=1250223480;
    SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes';
Viewing 3 replies - 16 through 18 (of 18 total)
  • Hi @rschilt,

    Unfortunately I have no way to test performance the site with all plug-ins removed and its not acceptable to leave our production site without navigation (the remaining plugins) for however long it takes until it crashes again.

    The site will only crash when it comes under heavy load (typically a spammer/hacker of some form).

    Thank you for your help thus far, I’ll let you know if the problems occur again. If they do then I’ll remove the remaining plug-ins as a last ditch effort.

    @aplji indeed these queries typically never show up in my slow query log, its only after an attack that the queries slow down.

    The site will only crash when it comes under heavy load (typically a spammer/hacker of some form).

    Ok. This changes things– a lot. You don’t have a database problem! You have a hacker problem. You need to be looking into protecting the site, not worrying about speeding up the queries. Look into plugins like Bad Behavior.

    Thanks @apljdi, I’ll give it a try.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Very slow database queries causing db errors’ is closed to new replies.