title: PostgreSQL server Connection error: could not connect to server
body: <p>I am using <code>pgAdmin4</code> and developing a <code>node.js</code> app.<br/>I had an abrupt shutdown of the computer and I can no longer connect to the <code>postgresql</code> server.  </p>
  
  <p>The error I get when trying to connect is : </p>
  
  <pre class="lang-sql prettyprint-override"><code>psql: could not connect to server: Connection refused (0x0000274D/10061)
               Is the server running on host "localhost" (::1) and 
               accepting TCP/IP connections on port 5432?
        could not connect to server: Connection refused (0x0000274D/10061)
               Is the server running on host "localhost" (127.0.0.1) and 
               accepting TCP/IP connections on port 5432?
  </code></pre>
  
  <p>I tried to run <code>postgres -D /usr/local/var/postgres/</code> as suggested in <a href="https://stackoverflow.com/questions/37307346/is-the-server-running-on-host-localhost-1-and-accepting-tcp-ip-connections">this SO answer</a>.<br/> However it gave me the following error : </p>
  
  <pre class="lang-sql prettyprint-override"><code>postgres: could not access directory "usr/loval/var/postgres": No such file or directory
  Run initdb or pg_basebackup to initialize a PostgreSQL data directory. 
  </code></pre>
  
  <p>So I just manually deleted the <code>postmaster.pid</code> file inside the <code>PostgreSQL/.../data</code> folder. <br/>But I still cannot connect to the database server.  </p>
  
  <p>I have checked the <code>postgresql.conf</code> file, and 
  the listen addresses is already set as <code>listen_addresses = '*'</code>, and the port is set to <code>5432</code>.</p>
  
  <p>I also tried deleting the pgAdmin file in the AppData/Roaming folder.<br/>But it gave me an error:</p>
  
  <pre class="lang-sql prettyprint-override"><code>The application server could not be contacted
  </code></pre>
  
  <p>and then afterwards the same problem of not being able to connect to the server happens.</p>