user warning: Table './stockvalues/cms_cache_form' is marked as crashed and should be repaired query: UPDATE cms_cache_form SET data = 'a:21:{s:6:\"choice\";a:3:{s:5:\"#type\";s:6:\"radios\";s:14:\"#default_value\";i:-1;s:8:\"#options\";a:4:{i:0;s:7:\"Bullish\";i:1;s:7:\"Bearish\";i:2;s:7:\"Neutral\";i:3;s:26:\"I don't play the game\";}}s:4:\"vote\";a:3:{s:5:\"#type\";s:6:\"submit\";s:6:\"#value\";s:4:\"Vote\";s:7:\"#submit\";a:1:{i:0;s:9:\"poll_vote\";}}s:5:\"#node\";O:8:\"stdClass\":39:{s:3:\"nid\";s:4:\"1886\";s:4:\"type\";s:4:\"poll\";s:8:\"language\";s:0:\"\";s:3:\"uid\";s:1:\"7\";s:6:\"status\";s:1:\"1\";s:7:\"created\";s:10:\"1251845680\";s:7:\"changed\";s:10:\"1251845925\";s:7:\"comment\";s:1:\"2\";s:7:\"promote\";s:1:\"1\";s:8:\"moderate\";s:1:\"0\";s:6:\"sticky\";s:1:\"0\";s:4:\"tnid\";s:1:\"0\";s:9:\"translate\";s:1:\"0\";s:3:\"vid\";s:4:\"4961\";s:12:\"revision_uid\";s:1:\"7\";s:5:\"title\";s:73:\"Are you currently bullish or bearish on the economy and the stock market?\";s:4:\"body\";s:0:\"\";s:6:\"teaser\";s:58:\"* Bullish\\n* Bearish\\n* Neutral\\n* I don\'t play the game\\n\";s:3:\"log\";s:0:\"\";s:18:\"revision_timestamp\";s:10:\"1251845925\";s:6:\"format\";s:1:\"0\";s:4:\"name\";s:11:\"Jake Berzon\";s:7:\"picture\";s:46:\"/home/stockvalues/stuff/pictures/picture-7.jpg\";s:4:\"data\";s:550:\"a:15:{s:7:\"contact\";i:1;s:3:\"DOB\";a:3:{s:4:\"year\";s:4:\"1965\";s:5:\"month\";s:1:\"9\";s:3:\"day\";s:2:\"25\";}s:6:\"sn_248\";i:1;s:8:\"sn_email\";s:16:\"\";s:9:\"sn_update\";s:6:\"Update\";s:14:\"picture_delete\";i:0;s:14:\"picture_upload\";s:0:\"\";s:13:\"form_build_id\";s:48:\"form-AwrEyk90gRPyqsDBwC2PS322yr_mvINhTCrUFPrO-5w\";s:5:\"fbuid\";s:9:\"581973933\";s:10:\"fb_visible\";i:1;s:9:\"fb_avatar\";i:0;s:13:\"fbstream_user\";s:1:\"5\";s:34:\"user_relationship_mailer_send_mail\";i:1;s:34:\"user_relationships_ui_auto_approve\";a:1:{i:1;i:0;}s:18:\"admin_compact_mode\";b:0;}\";s:7:\"runtime\";s:1:\"0\";s:6:\"active\";s:1:\"1\";s:6:\"choice\";a:4:{i:0;a:3:{s:6:\"chtext\";s:7:\"Bullish\";s:7:\"chvotes\";s:2:\"57\";s:7:\"chorder\";s:1:\"0\";}i:1;a:3:{s:6:\"chtext\";s:7:\"Bearish\";s:7:\"chvotes\";s:2:\"53\";s:7:\"chorder\";s:1:\"1\";}i:2;a:3:{s:6:\"chtext\";s:7:\"Neutral\";s:7:\"chvotes\";s:2:\"32\";s:7:\"chorder\";s:1:\"2\";}i:3;a:3:{s:6:\"chtext\";s:21:\"I don\'t play the game\";s:7:\"chvotes\";s:2:\"39\";s:7:\"chorder\";s:1:\"3\";}}s:10:\"allowvotes\";b:1;s:4:\"vote\";i:-1;s:4:\"path\";s:14:\"bull-bear-poll\";s:29:\"user_relationship_node_access\";b:0;s:22:\"last_comment_timestamp\";s:10:\"1349639940\";s:17:\"last_comment_name\";s:0:\"\";s:13:\"comment_count\";s:1:\"1\";s:8:\"taxonomy\";a:0:{}s:4:\"iids\";a:0:{}s:9:\"nodewords\";a:2:{s:11:\"description\";a:1:{s:5:\"value\";s:160:\"As autumn approaches the mood on Wall Street often shifts. This poll asks the bull vs. bear question in order to see if Main Street is in tune with Wall Street.\";}s:8:\"keywords\";a:1:{s:5:\"value\";s:40:\"Wall Stree, Main Stree, bull, bear, poll\";}}s:8:\"readmore\";b:0;s:5:\"links\";a:3:{s:16:\"comment_comments\";a:4:{s:5:\"title\";s:9:\"1 comment\";s:4:\"href\";s:9:\"node/1886\";s:10:\"attributes\";a:1:{s:5:\"title\";s:42:\"Jump to the first comment of this posting.\";}s:8:\"fragment\";s:8:\"comments\";}i:0;a:3:{s:5:\"title\";s:11:\"Older polls\";s:4:\"href\";s:4:\"poll\";s:10:\"attributes\";a:1:{s:5:\"title\";s:36:\"View the list of polls on this site.\";}}i:1;a:3:{s:5:\"title\";s:7:\"Results\";s:4:\"href\";s:17:\"node/1886/results\";s:10:\"attributes\";a:1:{s:5:\"title\";s:30:\"View the current poll results.\";}}}}s:6:\"#block\";b:1;s:6:\"#cache\";b:1;s:6:\"#theme\";s:9:\"poll_vote\";s:11:\"#parameters\";a:4:{i:0;s:16:\"poll_view_voting\";i:1;a:3:{s:7:\"storage\";N;s:9:\"submitted\";b:0;s:4:\"post\";a:0:{}}i:2;r:15;i:3;b:1;}s:9:\"#build_id\";s:48:\"form-fI1CtHfUN40S_GvEM4gBL1jMw-O_5RXFdAKDIl1Lwoo\";s:5:\"#type\";s:4:\"form\";s:11:\"#programmed\";b:0;s:13:\"form_build_id\";a:4:{s:5:\"#type\";s:6:\"hidden\";s:6:\"#value\";s:48:\"form-fI1CtHfUN40S_GvEM4gBL1jMw-O_5RXFdAKDIl1Lwoo\";s:3:\"#id\";s:48:\"form-fI1CtHfUN40S_GvEM4gBL1jMw-O_5RXFdAKDIl1Lwoo\";s:5:\"#name\";s:13:\"form_build_id\";}s:7:\"form_id\";a:3:{s:5:\"#type\";s:6:\"hidden\";s:6:\"#value\";s:16:\"poll_view_voting\";s:3:\"#id\";s:21:\"edit-poll-view-voting\";}s:3:\"#id\";s:16:\"poll-view-voting\";s:12:\"#description\";N;s:11:\"#attributes\";a:0:{}s:9:\"#required\";b:0;s:5:\"#tree\";b:0;s:8:\"#parents\";a:0:{}s:7:\"#method\";s:4:\"post\";s:7:\"#action\";s:54:\"/how-to-stop-drupal-crashing-linux-apache-mysql-server\";s:9:\"#validate\";a:1:{i:0;s:25:\"poll_view_voting_validate\";}}', created = 1510965525, expire = 1510987125, headers = '', serialized = 1 WHERE cid = 'form_form-fI1CtHfUN40S_GvEM4gBL1jMw-O_5RXFdAKDIl1Lwoo' in /home/stockvalues/public_html/includes/ on line 112.

If you are using Drupal 6 or an earlier version of this popular open source content management system, commonly installed on Linux servers running Apache and MySQL, to manage your content, you may have a problem. It is the same even if you managed to install Drupal in a much less common environment such as Windows, or are running it on a PostgreSQL database. The problem I am talking about lurks inside Drupal's core search module. Supposedly, it was fixed starting with Drupal 7, but I didn't check this personally.

Drupal's optional core search module is the one that makes internal site searches possible by parsing the site's nodes by the keywords that they contain. The module also scores the keywords it collects by the criteria set up in the module's admin interface, indexes them and stores results in the four MySQL database search tables: search_dataset, search_index, search_node_links and search_total. Even though this search module is optional, it is enabled by default at installation and most Drupal sites keep it that way.

That’s all good, except that this search module indexes both published and unpublished nodes. Now, what’s the problem with that? Well, we live in the world full of spammers and the way many good Drupal site administrators deal with all the unwanted “content” that spammers generate is not by deleting spam entirely, but by unpublishing it. In many other setups, all content must be approved by admins explicitly and that which is not, remains unpublished.

Now imagine a very likely scenario of a site with a thousand published real content articles and a hundred times as many unpublished spam articles. Also presume that each unit of spam is two to three times the length of real published content – somehow spammers always have that much more to say! All that unpublished spam grows the four Drupal MySQL search tables and it grows them a lot.

In our case, the largest of these MySQL database search tables, search_index alone grew to over 20 million keyword records and took up almost a gigabyte of database storage space. For a site with relatively little real content, this was an unjustifiably high load, which caused the MySQL database server to timeout on a nearly daily basis often taking the co-resident application server down with it. Something had to be done.

To solve the problem, I slightly hacked the node_update_index() function to restrict search indexing to only the published nodes. I then truncated all the four MySQL search tables and rebuilt the indexes. When all was done, the MySQL search_index table was only 35 thousand keywords long and took just over two megabytes of database space.

If you are in a similar situation, you may appreciate following my three easy steps to save your server from crashing all the time:

  1. Find the node_update_index() function inside the node.module file located in the modules/node directory of your Drupal installation. Change the WHERE clause of the SELECT statement used in this function from WHERE d.sid IS NULL OR d.reindex <> 0 to WHERE (d.sid IS NULL OR d.reindex <> 0) AND n.status=1. Remember to again apply this patch every time you upgrade Drupal 6 core.

  2. Empty the four Drupal MySQL search tables by issuing TRUNCATE TABLE search_dataset; TRUNCATE TABLE search_index; TRUNCATE TABLE search_node_links; TRUNCATE TABLE search_total; commands from MySQL command line or by using phpMyAdmin to do it.

  3. To rebuild the search indexes, go to your Drupal website’s /admin/settings/search url and click on the “Re-index site” button. Drupal will take it from here, or you can expedite the rebuilding of your site’s search indexes by running cron manually a few times until you see the “100% of the site has been indexed. There are 0 items left to index.” message above the “Re-index site” button. To run cron manually, go to your Drupal website’s /admin/reports/status/run-cron url.

Good luck!

MySQL logo

Why would you ever want to leave spam unpublished? With appropriately set user permissions around node creation, plus the proper configuration of one or more modules (e.g. spambot, honeypot, spamicide, mollom) spam should be prevented from entering the site at all. It isn't just fat search tables you should be worried about.

Drupal's core search module is no performance poster-child even when running smoothly. In my experience though, sites that allow unchecked content creation (including comments) are more likely to break from the strain of being hammered by automated spam submissions than from legitimate users attempting to use search on a bloated index.

Maintaining hacked versions of core or contrib modules is rarely a winning strategy; you might not mind the burden of remembering about it and manually patching Drupal each time you update, but one day someone else might be maintaining the site and they'll have no idea about your modifications.

You are absolutely right, there are other ways to deal with Spam, especially if you are doing a brand new Drupal install. However, this is great a fix for an older Drupal installation that was allowed to get out of hand in the first place. It is not necessarily a best practice for a new Drupal installation, but why would you do a brand new install of such an old version of Drupal now anyway?!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <p> <br> <tr> <td> <table>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.

User login


Are you currently bullish or bearish on the economy and the stock market?:

Email Center




New Users
Lost Password
I Need Help

Who's online

There are currently 0 users and 6 guests online.