title: PG::ConnectionBad Postgres Cluster down
body: <p>Digitalocean disabled my droplet's internet access. After fixing the error (rollback to older backup) they restored the internet access. But afterwards I constantly get an error when deploying, I can't seem to get my Postgres database up and running.</p>
  
  <p>I'm getting an error each time I try to deploy my application.</p>
  
  <pre><code>PG::ConnectionBad: could not connect to server: No such file or directory
      Is the server running locally and accepting
      connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
  </code></pre>
  
  <p>So I used SSH to login to my server and check if my Postgres was actually running with:</p>
  
  <p><code>pg_lsclusters</code></p>
  
  <p><strong>Results into:</strong></p>
  
  <p><code>Ver Cluster Port Status Owner    Data directory               Log file
  9.5 main    5432 down   postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log</code></p>
  
  <p><strong>Postgres server status</strong></p>
  
  <p>So my Postgres server seems to be down. I tried putting it 'up' again with:</p>
  
  <p><code>pg_ctlcluster 9.5 main start</code> After doing so I got the error: <code>Insecure directory in $ENV{PATH} while running with -T switch at /usr/bin/pg_ctlcluster line 403.</code></p>
  
  <p>And <code>/usr/bin/pg_ctlcluster</code> on line 403 says:</p>
  
  <p><code>system 'systemctl', 'is-active', '-q', "postgresql\@$version-$cluster";</code>
  But I'm not to sure what the problem could be here and how I could fix this.</p>
  
  <h2>Update</h2>
  
  <p>I also tried updating the permissions on <code>/bin</code> to 755 as mentioned <a href="https://ubuntuforums.org/showthread.php?t=882648" rel="nofollow noreferrer">here</a>. Sadly that did not fix my problem.</p>
  
  <h2>Update 2</h2>
  
  <p>I changed the /usr/bin to 755. Now when I try <code>pg_ctlcluster 9.5 main start</code>, I get this: </p>
  
  <blockquote>
    <p>Job for postgresql@9.5-main.service failed because the control process exited with error code. See "systemctl status postgresql@9.5-main.service" and "journalctl -xe" for details.</p>
  </blockquote>
  
  <p>And inside the <code>systemctl status postgresql@9.5-main.service</code>:</p>
  
  <pre><code>postgresql@9.5-main.service - PostgreSQL Cluster 9.5-main
     Loaded: loaded (/lib/systemd/system/postgresql@.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2018-01-28 17:32:38 EST; 45s ago
    Process: 22473 ExecStart=postgresql@%i --skip-systemctl-redirect %i start (code=exited, status=1/FAILURE)
  
  Jan 28 17:32:08 *url* systemd[1]: Starting PostgreSQL Cluster 9.5-main...
  Jan 28 17:32:38 *url* postgresql@9.5-main[22473]: The PostgreSQL server failed to start.
  Jan 28 17:32:38 *url* systemd[1]: postgresql@9.5-main.service: Control process exited, code=exited status=1
  Jan 28 17:32:38 *url* systemd[1]: Failed to start PostgreSQL Cluster 9.5-main.
  Jan 28 17:32:38 *url* systemd[1]: postgresql@9.5-main.service: Unit entered failed state.
  Jan 28 17:32:38 *url* systemd[1]: postgresql@9.5-main.service: Failed with result 'exit-code'.
  </code></pre>
  
  <hr>
  
  <p>Thanks!</p>