title: Express.js app times out when attempting to query a PostgreSQL database
body: <p>I've built an <strong>Express.js</strong> app, hosted by <strong>Heroku</strong>, with a non-embedded <strong>PostgreSQL</strong> database.</p>
  <p>The app was running as intended until about a month ago, and for several months before that. However, when I logged in today, I ran into a serious problem.</p>
  <p><strong>Whenever I try to access any page which queries the database, it tries to load for a few seconds, and then gives me the standard Heroku &quot;Application Error&quot; page.</strong></p>
  <h2>Accessing the Database through Javascript</h2>
  <p>This is what a portion of my code that queries the database looks like:</p>
  <pre class="lang-js prettyprint-override"><code>var that = this;
  var title = &quot;The Journal&quot;;
  var queryString = &quot;SELECT * FROM JournalEntry &quot;+
                    &quot;ORDER BY theTimeStamp ASC;&quot;;
  var extract, data;
  const client = new Client({
      connectionString: process.env.DATABASE_URL,
      ssl: { rejectUnauthorized: false }
  });
  
  console.log(process.env.DATABASE_URL);
  console.log(&quot;Hello!&quot;);
  
  client.connect();
  
  console.log(&quot;My!&quot;);
  
  client.query(queryString, (err, result) =&gt; {
      if(err) throw err;
  
      console.log(&quot;Lovely!&quot;);
  
      extract = result.rows;
      data = interpretJournalExtract(extract);
      data = objectifyExtract(data);
      client.end();
      that.finaliser.protoRender(req, res, &quot;tabular&quot;,
                                 { title: title, data: data });
  });
  </code></pre>
  <p>And this is what the logs look like when I run this code:</p>
  <pre><code>2021-03-02T16:12:14.780345+00:00 app[web.1]: postgres://stfonefosxlmgt:227d3914dfb105c6ad3db47ad854f771391b15c8dead2da0a691a66d25cb2f65@ec2-54-228-237-40.eu-west-1.compute.amazonaws.com:5432/de337svimlvbgo
  2021-03-02T16:12:14.780701+00:00 app[web.1]: Hello!
  2021-03-02T16:12:14.781269+00:00 app[web.1]: My!
  2021-03-02T16:12:44.784363+00:00 heroku[router]: at=error code=H12 desc=&quot;Request timeout&quot; method=GET path=&quot;/journal&quot; host=hgmj.herokuapp.com request_id=f28bdda2-f3bd-40b2-a894-e07cb9e0054c fwd=&quot;86.191.159.122&quot; dyno=web.1 connect=1ms service=30012ms status=503 bytes=0 protocol=http
  2021-03-02T16:12:44.785541+00:00 app[web.1]: GET /journal - - ms - -
  </code></pre>
  <p>You'll notice that the logs get to &quot;Hello!&quot; and &quot;My!&quot;, but not to &quot;Lovely!&quot;.</p>
  <h2>Accessing the Database through the Heroku CLI</h2>
  <p>It's also worth noting that I <em><strong>can</strong></em> access the database through the Heroku CLI, and this is what my screen looks like when I do so:</p>
  <pre><code>-&gt; Connecting to postgresql-curly-19296
  psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1), server 11.11 (Ubuntu 11.11-1.pgdg16.04+1))
  SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
  Type &quot;help&quot; for help.
  
  hgmj::DATABASE=&gt;
  </code></pre>
  <h2>The Bottom Line</h2>
  <p><strong>Why is this happening, and what can I do about it?</strong></p>