title: Database being overloaded by mysterious count query
body: <p>Periodically we have been having downtime on our site and we can't explain it. It's pretty sporadic without any noticeable patterns, but in the past 24 hours, we've had 6 instances.</p>
  
  <p>When we have the downtime, it seems to be that the database is being overloaded by a particular query (see image):</p>
  
  <p><code>SELECT COUNT(*) FROM "cache"</code> </p>
  
  <p>We've looked at all the code and workers and can't find anywhere in the code executing a count of this table. </p>
  
  <p>Does anyone have any ideas of how Django might be translating a query into a count, other than an explicit <code>count()</code> or <code>len()</code>? Or could this be the work of hackers? Any input would be greatly appreciated. </p>
  
  <p><a href="https://i.stack.imgur.com/0CsEx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0CsEx.png" alt="enter image description here"></a></p>
  
  <p>UPDATE - tried changing the Postgres password and we're still seeing these mysterious queries. We are not 100% sure if it's related to the downtime, but we are pretty sure.</p>
  
  <p>UPDATE2 - just in case people have this problem in future, the issue was that our cache table was hitting the limit of size. We deleted the entire cache table, which cause instability on the site for about 5 min, and then suddenly got much faster and solved the problem! And yes, it turns out the cache table is hit with expensive queries via the Django admin panel, but clearing the cache helped reduce that burden.</p>