Connections using pg-promise
<p>So I'm using pg-promise to query my database. Since I'm using heroku postgres (free version), the maximum number of connections is 20. </p>

<p>To connect to the db, I use</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>pgp(process.env.DATABASE_URL + '?poolSize=10')
  .connect()
  .then( sco =&gt; {
    dbclient = sco;
  })
  .catch( err =&gt; {
    console.error(err);
  })</code></pre>
</div>
</div>
</p>

<p>I'm using the dbclient variable to run queries, e.g. </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>dbclient
  .one('select ...')
  .then(() =&gt; ...)
  .catch( res.status(500).send);</code></pre>
</div>
</div>
</p>

<p>Even though I'm setting the pool size to 10, the number of connections increases indefinitely and my app crashes. </p>

<p>How can I solve this? Do I have to release the client each time I run a query?</p>

<p>EDIT:</p>

<p>So I edited my code, this is exactly how I'm using it now, and I still have the same problem.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const pgp = require('pg-promise')();
pgp.pg.defaults.poolSize = 10;

router.get('/', (req, res) =&gt; {
  pgp(process.env.DATABASE_URL).any('select ...')
        .then((result) =&gt; res.status(200).send(result))
        .catch(err =&gt; res.status(500).send({err}));
});</code></pre>
</div>
</div>
</p>