• We are getting server errors every 20~ minutes that now and then cause the website to crash and show “error establishing a database connection”.

    The error is always the same

    message: Database error MySQL server has gone away to query SELECT COUNT(DISTINCT(relevanssi.doc)) FROM wp_relevanssi AS relevanssi
    			 WHERE (relevanssi.term LIKE 'משחק%' OR relevanssi.term_reverse LIKE CONCAT(REVERSE('משחק'), '%'))   AND relevanssi.doc NOT IN (
    						SELECT DISTINCT(tr.object_id)
    							FROM wp_term_relationships AS tr
    							WHERE tr.term_taxonomy_id IN (6,9)) AND  relevanssi.doc IN (
    			SELECT DISTINCT(tr.object_id)
    			FROM wp_term_relationships AS tr
    			WHERE tr.term_taxonomy_id IN (20,27,103,4329,4341,4395,4446,4450,4451,4452,4483,4484,4539,4569,4778,6067,6547,6664,6796,3184,4444,4445,4775,4912,7618,8708,4448,4449,4896,7899,8757,8758,4914,4543,7552,8815,6665,6667,8294,8295)
    		) AND  relevanssi.doc IN (
    			SELECT DISTINCT(tr.object_id)
    			FROM wp_term_relationships AS tr
    			WHERE tr.term_taxonomy_id IN (20,27,103,4329,4341,4395,4446,4450,4451,4452,4483,4484,4539,4569,4778,6067,6547,6664,6796,3184,4444,4445,4775,4912,7618,8708,4448,4449,4896,7...PHP

    Why is it even being requested so often?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Someone does a search every ~20 minutes? That’s a normal Relevanssi database query.

    What’s unusual about it is the duplicated taxonomy restriction, but other than that this is a very straightforward Relevanssi search query that should not cause any database problems on a healthy database.

    I would recommend asking your hosting provider about this, perhaps they can offer some guidance on this.

    That taxonomy restriction does look a bit odd, what kind of tax_query filtering you are using in the search?

    Thread Starter nivsp

    (@spektorniv)

    Thanks for the quick reply.

    The weird thing is, it’s the exact same query that runs into MySQL exhaustion.
    All other search queries have no errors.
    I tried to replicate the problem my self but when I search for this word it works perfectly.
    I turned the plugin off 90 minutes ago and it stopped the error from showing up.

    Can you explain your question?

    Plugin Author Mikko Saari

    (@msaari)

    You have this appear twice in the problem query:

    AND  relevanssi.doc IN (
    SELECT DISTINCT(tr.object_id)
    FROM wp_term_relationships AS tr
    WHERE tr.term_taxonomy_id IN (20,27,103,4329,4341,4395,4446,4450,4451,4452,4483,4484,4539,4569,4778,6067,6547,6664,6796,3184,4444,4445,4775,4912,7618,8708,4448,4449,4896,7899,8757,8758,4914,4543,7552,8815,6665,6667,8294,8295)
    )

    This adds a restriction that the search results must be within these 40 categories (or other taxonomies). This restriction appears twice. Why? Is it something that is done on purpose? Does this appear in normal searches that don’t exhaust the MySQL server?

    If you install Query Monitor, you can use it to look at the Relevanssi query. If you check a working Relevanssi query with the Query Monitor, does the same taxonomy restriction appear there as well? If it does, then that’s not the problem, but if it doesn’t, that looks like the problem.

    Your hosting provider should be able to help you figure out if these problem queries are related to specific action on your site. If these problem queries happen at certain intervals, perhaps there’s some bot that visits your site doing a problematic query that causes this? That’s one possibility.

    Thread Starter nivsp

    (@spektorniv)

    After some research, it turned out to be Google Bot.
    We disabled the plugin and now everything is running as it should.
    We consulted with the hosting providers and they said they can’t help as long as it is Google’s Bot and the intervals are so “normal” (makes sense).

    I am not really sure though why the query looks like it. Other queries don’t have these restrictions. Is there any way to make sure from the plugin side that it won’t return?

    Obviously, we want to plugin up and running.

    Plugin Author Mikko Saari

    (@msaari)

    Since it’s Google Bot, that should be easy: Google Bot listens to robots.txt, so if you tell it in your robots.txt that your search pages are out of bounds, it should not go there. That would be good, because Google isn’t supposed to index your search result pages in the first place.

    You can look at the server access logs to see the exact URL the Google Bot is visiting: the taxonomy restrictions should appear in that URL. You can then probably block access to that URL completely.

    You can also try adding this to your theme functions.php:

    add_filter( 'relevanssi_search_ok', 'rlv_stop_google_bot' );
    function rlv_stop_google_bot( $ok ) {
      if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
        if ( false !== stristr( $_SERVER['HTTP_USER_AGENT'], 'google' ) ) {
          $ok = false;
        }
        if ( false !== stristr( $_SERVER['HTTP_USER_AGENT'], 'bot' ) ) {
          $ok = false;
        }
      }
      return $ok;
    }

    This will look for the user agent value from the searcher and if it contains “google” or “bot”, it will stop Relevanssi from running.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Database error’ is closed to new replies.