I am now running a PostgreSQL inside a Docker inside a EC2, and a Node.js instance is connecting to it.

I recently found that the connection is becoming slower. Before, restarting the instance only need a few seconds to establish the connection. But now, it requires about 30+ seconds.

I wonder what could be happening there and how can I optimize it. It never happened to me before.

  • Is the node.js running on the same EC2 instance as the database but in a different docker container? Or on a different machine? Did the problem only appear upon the reboot, or did it appear before and the reboot just failed to fix it? How are you measuring the connection time? What if you connect with something simpler to trouble-shoot, like psql or pgbench?
    – jjanes
    Jun 24, 2023 at 20:28
  • @jjanes The Node.js instance is running directly in the EC2 instance's linux system, not in a container. The problem happens on rebooting the Node.js itself (not the EC2). I measure the connection time by seeing the log (there are 2 different lines of log, one prints before the connection and another prints after it). Jun 24, 2023 at 20:34
  • Your description isn't enough to know what is going on. Node connection management can be complex. You either need to show the code, or recapitulate the issue in something else, like psql.
    – jjanes
    Jun 26, 2023 at 15:27


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.