Is the server running on host “localhost” (::1) an

2020-01-30 03:39发布

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:

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?

13条回答
Melony?
2楼-- · 2020-01-30 03:52

If you want to restart Postgresql on Linux, then you have to use the following command.

/etc/init.d/postgresql restart

查看更多
Summer. ? 凉城
3楼-- · 2020-01-30 03:57

I had almost just as same error with my Ruby on Rails application running postgresql(mac). This worked for me:

brew services restart postgresql
查看更多
The star\"
4楼-- · 2020-01-30 04:00

This can be as pid file created for postgress have not been deleted due to unexpected shutdown. So to fix this, remove this pid file.

  1. Find the postgres data directory. On a MAC using homebrew it is /usr/local/var/postgres/, other systems it might be /usr/var/postgres/

  2. Remove pid file

    rm postmaster.pid

  3. Restart postgress. On Mac,

    brew services restart postgresql

查看更多
太酷不给撩
5楼-- · 2020-01-30 04:01

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/)

查看更多
叼着烟拽天下
6楼-- · 2020-01-30 04:04

This worked for me: run

sudo lsof -i :<port_number>

after that it will display the PID which is currently attached to the process.

After that run sudo kill -9 <PID>

if that doesn't work, try the solution offered by user8376606 it would definitely work!

查看更多
够拽才男人
7楼-- · 2020-01-30 04:05

It might be as simple as the postgresql service is down. Try running:

sudo service postgresql start

which fixed the issue for me.

查看更多
登录 后发表回答