title: How to set query_timeout in relation to statement_timeout?
body: <p>We can set 2 timeouts for the <a href="https://node-postgres.com/api/client#constructor" rel="noreferrer">Client</a>:</p>
  
  <ul>
  <li><code>statement_timeout</code>: number of milliseconds before a statement in query will time out, default is no timeout</li>
  <li><code>query_timeout</code>
  number of milliseconds before a query call will timeout, default is no timeout</li>
  </ul>
  
  <p>I understand it like this: </p>
  
  <ul>
  <li>the <code>statement_timeout</code> will be passed to the database (see <a href="https://www.postgresql.org/docs/11/runtime-config-client.html#GUC-STATEMENT-TIMEOUT" rel="noreferrer">postgres-docs:statement_timeout</a>) and when a statement takes longer than this, the database will abort the query and return an error</li>
  <li>the database does not know anything about the <code>query_timeout</code>. This is handled by the drive (<code>node-postgres</code>). When this timeout is reached, <code>node-postgres</code> will just stop listening for a response, but the database may still be executing the query</li>
  </ul>
  
  <p><strong>Question 1</strong> Should we set the query timeout slightly longer than the statement timeout?</p>
  
  <p>I think so because then:</p>
  
  <ol>
  <li>when a query really takes too long, the db will abort the query and return the error to the client</li>
  <li>when the application does not get any response from the server within the query-timeout the application will throw a timeout error<br>
  <strong>Question 2</strong>: what could be the reason for this? e.g. problems with the TCP/IP connection?</li>
  </ol>
  
  <h2>Transactions</h2>
  
  <p>What is the situation when we use transactions?<br>
  e.g. when we look at the <a href="https://node-postgres.com/features/transactions#Examples" rel="noreferrer">example from the docs</a>:</p>
  
  <pre class="lang-js prettyprint-override"><code>  try {
      await client.query('BEGIN')
      const queryText = 'INSERT INTO users(name) VALUES($1) RETURNING id'
      const res = await client.query(queryText, ['brianc'])
      const insertPhotoText = 'INSERT INTO photos(user_id, photo_url) VALUES ($1, $2)'
      const insertPhotoValues = [res.rows[0].id, 's3.bucket.foo']
      await client.query(insertPhotoText, insertPhotoValues)
      await client.query('COMMIT')
    } catch (e) {
      await client.query('ROLLBACK')
      throw e
    }
  </code></pre>
  
  <p>So in the happy path, we call <code>query()</code> 5 times: and the query/statement timouts are applied per <code>query()</code> call.<br>
  <strong>Question 3</strong> So also the <code>BEGIN</code>/<code>COMMIT</code> queries have the same timeout a the <code>INSERT</code> queries, right?</p>