By no means this is a usual thing, but since there’s very little information (in fact only one link that gives no real answers) on what to do when you see the error below upon publishing a post, I decided to share the solution:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/…/public_html/wp-includes/wp-db.php on line 170

The error points to an innocent line that removes single quotes from a database query, and it’s misleading. One of the real causes for this problem may lay in the slug (post name) field. You can see this field in the Permalink line below the Title field in your post editor; it’s emphasized.

In my case, there was an endless attempt to find a unique name for a post having an HTML entity (long dash) in its slug. Even though it was correctly encoded with %NN sequences, the database sever had hard time executing the query correctly. So, the first check on your list is:

Make sure your post slug (that symbolic part of the permalink) has no special symbols, but only letters, digits and dashes.