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 anmvp
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?
First I tried
Second I tried
So I just restarted my mac to restore all ports back and it worked for me.
I resolved the issue via this command
At times, you might get this error
So, try running the following command and then run the first command given above.
Most likely it's because your system shutdown unexpectedly
Try
You might see
Then try
example
And it should start postgres normally
This worked in my case:
For Docker users: In my case it was caused by excessive docker image size. You can remove unused data using
prune
command:Warning: as per manual (
docker system prune --help
):I often encounter this problem on windows,the way I solved the problem is Service - Click PostgreSQL Database Server 8.3 - Click the second tab "log in" - choose the first line "the local system account".