title: Why are Google Cloud SQL connections failing: "(psycopg2.DatabaseError) server closed the connection unexpectedly"
body: <p>I am working with a customer who is having issues with their GCP Cloud SQL deployment. There questions are transcribed here:</p>
  
  <p>When connecting to Cloud SQL, connections often fail intermittently. This can look like a Python error:</p>
  
  <pre><code>(psycopg2.DatabaseError) server closed the connection unexpectedly
      This probably means the server terminated abnormally
      before or while processing the request.
  </code></pre>
  
  <p>Or, in Node, it can look like a timeout error or a socket hang up:</p>
  
  <pre><code>TimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
  </code></pre>
  
  <p>We have everything configured correctly, as far as we can tell, and have followed all the instructions in the Cloud SQL troubleshooting guide. We have an instance with 20GB of memory that should support 250 connections. The timeouts should be set to refresh the connections at the right intervals (&lt; 10 min). So we're not sure what's going on here.</p>
  
  <p>I know that isn't a ton to go on but I wanted to try and do my due diligence in seeing how we can help them. I realize we may not get a perfect answer on what is going on but some additional questions I can ask of them to help debug the issue would be a great help to start with.</p>
  
  <p>I found this similar question that seems to be describing the same issue but it has no answers: <a href="https://stackoverflow.com/questions/34665652/postgresql-sever-closed-the-connection-unexpectedly">PostgreSQL &#39;Sever closed the connection unexpectedly&#39;</a></p>
  
  <p>Thanks for any help!</p>