Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

Before anything, please note that I have found several similar questions on Stack Overflow and articles all over the web, but none of those helped me fix my issue:

  • PG Error could not connect to server: Connection refused Is the server running on port 5432?
  • PG::ConnectionBad - could not connect to server: Connection refused
  • psql: could not connect to server: Connection refused

Now, here is the issue:

  • I have a Rails app that works like a charm.
  • With my collaborator, we use GitHub to work together.
  • We have a master and an mvp branches.
  • I recently updated my git version with Homebrew (Mac).
  • We use Foreman to start our app locally.

Now, when I try to launch the app locally, I get the following error:

PG::ConnectionBad at / could not connect to server: Connection refused     Is the server running on host "localhost" (::1) and accepting     TCP/IP connections on port 5432? could not connect to server: Connection refused     Is the server running on host "localhost" (127.0.0.1) and accepting     TCP/IP connections on port 5432? 

I tried to reboot my computers several times.

I also checked the content of /usr/local/var/postgres:

PG_VERSION      pg_dynshmem     pg_multixact    pg_snapshots    pg_tblspc       postgresql.conf base            pg_hba.conf     pg_notify       pg_stat         pg_twophase     postmaster.opts global          pg_ident.conf   pg_replslot     pg_stat_tmp     pg_xlog         server.log pg_clog         pg_logical      pg_serial       pg_subtrans     postgresql.auto.conf 

As you can see, there is no postmaster.pid file in there.

Any idea how I could fix this?

like image 862
Thibaud Clement Avatar asked May 18 '16 18:05

Thibaud Clement


People also ask

What is running on port 5432?

Port 5432 is already in use Usually this means that there is already a PostgreSQL server running on your Mac. If you want to run multiple servers simultaneously, use different ports.

Could not connect to server Connection refused Is the server running on host?

“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.

Can't connect to server connection refused PostgreSQL windows?

If the connection is still failing, then there might be a permission issue in the pg_hba. conf access configuration file. Make sure this is set up correctly to accept connections from your IP. Finally, ensure there are no firewalls or iptables on the Postgres server that are blocking connections.


2 Answers

run postgres -D /usr/local/var/postgres and you should see something like:

 FATAL:  lock file "postmaster.pid" already exists  HINT:   Is another postmaster (PID 379) running in data directory "/usr/local/var/postgres"? 

Then run kill -9 PID in HINT

And you should be good to go.

like image 200
user8376606 Avatar answered Sep 28 '22 05:09

user8376606


You most likely ran out of battery and your postgresql server didn't shutdown correctly.

The easiest workaround is to download the official postgresql app and launch it: it will force the server to start (http://postgresapp.com/)

like image 29
Graham Slick Avatar answered Sep 28 '22 05:09

Graham Slick