title: Debugging Postgres ETIMEDOUT
body: <p>Over the last few days I've started to see <code>read ETIMEDOUT</code> errors in production, coming from Postgres (<a href="https://github.com/brianc/node-postgres" rel="nofollow noreferrer">with <code>node-postgres</code></a>) and I'm having a tough time getting to the source of the problem.</p>
  
  <p>I'm not sure whether the problem is that the database is unable to handle the connection, or whether it's something to do with being unable to acquire a connection from the pool, let alone write to the socket.</p>
  
  <p>I can't recreate the error in development at all (and I can't recreate reliably in production either). Nothing is showing up in the Postgres error logs though.</p>
  
  <p>Here's the pool configuration:</p>
  
  <pre><code>pool: { 
    max: 50, 
    min: 0, 
    idle: 20000, 
    acquire: 20000 
  }
  </code></pre>
  
  <p>As far as I can see, the maximum number of connections we've had concurrently over the last month is 8, so the pool should never have been depleted.</p>
  
  <p>Does Postgres have any kind of configurable query timeout that could be adjusted to make sure that long running queries aren't causing these? Although just for reference, sometimes these are happening for tiny inserts or single row reads.</p>
  
  <p>I'm fairly sure that <code>ETIMEDOUT</code> is a system error, not something thrown by the high level JavaScript drivers. Where is the timeout for the underlying socket defined?</p>