4

My postgres was working previously, but for some reason does not work anymore. I have tried several different searches in stack overflow and other sites, and after coming up with the same results and reading the same pages over and over again, without any success, it was time to post a new question.

Trying to run my rails project on the local host raises the following error message: 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"?

The server is not running at all, as indicated by the following output from ps -fu postgres:

postgres 23969 23968 0 09:54 pts/25 00:00:00 -bash

Error messages that I'm getting:

  • When running as the "postgres" user, executing psql results in:

psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

  • When trying to start postgres:

Other things I have tried:

  • Executing postgres -D /usr/local/pgsql/data >logfile 2>&1 & (as indicated by the official documentation) outputs: [1] 24670. But the server still doesn't run.

  • I also tried starting the server via service postgres start. This prompts me to my password to authenticate me as the user (it says Authentication is required to start 'postgres.service'.) My login succeeds (==== AUTHENTICATION COMPLETE ===)but then it says Failed to start postgres.service: Unit postgres.service not found.

  • I tried restarting the server (following these instructions using sudo /etc/init.d/postgresql restart), which in the past did fix postgres, but now simply prompts Restarting postgresql (via systemctl): postgresql.service. However, now I try to start the server again, and nothing has changed.

  • The problem does not seem to be any postmaster.pid file that I need to remove. After going through the same process that this user did, nothing was found when running sudo find / -name .s.PGSQL.5432 -ls

  • I have tried a clean install, and it still doesn't work. Nothing has changed, and the same error messages are appearing.

After removing postgres (following these instructions), I went through the digital ocean tutorial up to the point where it says "You can now access a Postgres prompt immediately by typing: psql".

Other possible factors: (I am at my wit's end, so I'm listing any possible factor that comes to mind)

  1. I am running Ubuntu Xenial (16.04), and postgresql 9.5
  2. I recently moved and am using a new Internet provider. I'm not sure why this would be an issue, but it did require me to change other settings (specifically, to deploy my rails project locally, instead of localhost:3000 I was using my inet addr. In other words, "http://:3000" (where is the number provided for inet by ifconfig). But after moving to a new Internet provider, my inet addr changed.
  3. [Update] Log files:

LOG: could not bind IPv4 socket: Cannot assign requested address HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. WARNING: could not create listen socket for "localhost" FATAL: could not create any TCP/IP sockets

At this point I spent several hours to no avail... Please help!!

migrated from stackoverflow.com Oct 28 '16 at 18:10

This question came from our site for professional and enthusiast programmers.

  • can you paste the result of pg_lsclusters – Nikhil Oct 28 '16 at 18:16
  • 9.5 main 5432 down postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log – RyanQuey Oct 28 '16 at 18:17
  • 1
    also paste for netstat -tulpn | grep :5432 – Nikhil Oct 28 '16 at 18:22
  • When I run that, I get (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.). when I run it using sudo, I get sudo: unable to resolve host <my_machine> – RyanQuey Oct 28 '16 at 18:29
  • 1
    Hi - this comment is for the next person with this problem. I was getting this error on a reinstall. I had previously remove-d postgres. In my case the configuration files did not all have owner: "postgres". So start was giving me: "Loaded: not-found (Reason: No such file or directory)" errors. Why? File owner. Evidently I'd edited a file and not reset the ownership. tsk, tsk tsk – will Mar 10 '17 at 14:05
0

The /etc/hosts file was incorrectly configured, due to some changes to that file previously. It did not cause trouble immediately, but for some reason changing the file back to defaults (i.e., 127.0.0.1 for the local host and 127.0.1.1 for my machine) solved the problem.

This was discovered by running netstat -tulpn | grep :5432, which gave the following error output: sudo: unable to resolve host <my_machine>. This pointed to the fact that there was a problem with the /etc/hosts file.

For a helpful resource, see this link.

  • Credit to Nikhil for pointing me to the answer. – RyanQuey Oct 28 '16 at 20:40
  • I'm fairly satisfied. I have to wait 2 days though. However, it would be nice to know why this solution actually worked (i.e., why this problem came up now rather than a few weeks ago when I 1st changed my /etc/hosts file). Also, any general principles on when to use netstat ? – RyanQuey Oct 29 '16 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.