title: Unable to connect to Postgres on EC2: ECONNREFUSED
body: <p>I have a Node server hosted on an EC2 instance that is trying to connect to Postgres running on the same instance. When I start the server I get an ECONNREFUSED error to the db:</p>
  
  <p><code>Unable to connect to the database: SequelizeConnectionRefusedError: connect ECONNREFUSED x.x.x.x:5432</code></p>
  
  <p>I am using the Sequelize ORM package from NPM:</p>
  
  <pre><code>import Sequelize from 'sequelize';
  const db = new Sequelize('postgres://postgres@52.9.136.53/unloadx' {dialect: 'postgres'});
  </code></pre>
  
  <p>Postgres is running on the instance, and I have port 5432 open in my inbound security rule. I can confirm that postgres is running with <code>ps aux | grep postgres</code> which shows multiple postgres related processes, and <code>netstat -anp --tcp</code> confirms that postgres appears to be listening on the port:</p>
  
  <pre><code>Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  tcp6       0      0 ::1:5432                :::*                    LISTEN      -
  </code></pre>
  
  <p>But when I scan the port with <code>nmap x.x.x.x -p 5432</code> it shows that the port status is closed. Per nmap, this means that the port is accessible but has no application listening on it able to respond to packets.</p>
  
  <p>Appreciate any help in getting the connection to work.</p>