服务器是在主机“localhost”(:: 1)上运行并在端口5432上接受TCP / IP连接吗?

时间:2022-10-19 18:57:32

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:

在此之前,请注意我在Stack Overflow和网上的文章中发现了几个类似的问题,但这些都没有帮助我解决我的问题:

Now, here is the issue:

现在,问题在于:

  • I have a Rails app that works like a charm.
  • 我有一个Rails应用程序,就像一个魅力。
  • With my collaborator, we use GitHub to work together.
  • 通过我的合作者,我们使用GitHub一起工作。
  • We have a master and an mvp branches.
  • 我们有一个master和一个mvp分支。
  • I recently updated my git version with Homebrew (Mac).
  • 我最近用Homebrew(Mac)更新了我的git版本。
  • We use Foreman to start our app locally.
  • 我们使用Foreman在本地启动我们的应用程序。

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:

我还检查了/ 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.

如您所见,那里没有postmaster.pid文件。

Any idea how I could fix this?

知道如何解决这个问题吗?

10 个解决方案

#1


22  

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

你很可能没电了,你的postgresql服务器没有正确关机。

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

最简单的解决方法是下载官方postgresql应用程序并启动它:它将强制服务器启动(http://postgresapp.com/)

#2


23  

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

运行postgres -D / usr / local / var / postgres你应该看到类似的东西:

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

然后在HINT中运行kill -9 PID

And you should be good to go.

你应该好好去。

#3


11  

Most likely it's because your system shutdown unexpectedly

很可能是因为您的系统意外关闭

Try

尝试

postgres -D /usr/local/var/postgres

You might see

你可能会看到

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

Then try

然后试试

kill -9 PID

example

kill -9 419

And it should start postgres normally

它应该正常开始postgres

#4


9  

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

它可能就像postgresql服务失败一样简单。试试跑步:

sudo service postgresql start

which fixed the issue for me.

这解决了我的问题。

#5


5  

This worked in my case:

这适用于我的情况:

brew uninstall postgresql
rm -fr /usr/local/var/postgres/
brew install postgresql

#6


0  

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".

我经常在Windows上遇到这个问题,我解决问题的方法是服务 - 点击PostgreSQL数据库服务器8.3 - 点击第二个标签“登录” - 选择第一行“本地系统帐户”。

#7


0  

This worked for me: run

这对我有用:跑

sudo lsof -i :<port_number>

sudo lsof -i:

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

之后它将显示当前附加到过程的PID。

After that run sudo kill -9 <PID>

之后运行sudo kill -9

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

如果这不起作用,尝试user8376606提供的解决方案,它肯定会工作!

#8


0  

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

如果要在Linux上重新启动Postgresql,则必须使用以下命令。

/etc/init.d/postgresql restart

/etc/init.d/postgresql重启

#9


0  

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.

这可以是因为意外关闭而没有删除为postgress创建的pid文件。因此,要解决此问题,请删除此pid文件。

  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/

    找到postgres数据目录。在使用自制软件的MAC上,它是/ usr / local / var / postgres /,其他系统可能是/ usr / var / postgres /

  2. Remove pid file

    删除pid文件

    rm postmaster.pid

    rm postmaster.pid

  3. Restart postgress. On Mac,

    重新启动postgress。在Mac上,

    brew services restart postgresql

    brew服务重启postgresql

#10


0  

I resolved the issue via this command

我通过这个命令解决了这个问题

pg_ctl -D /usr/local/var/postgres start

At times, you might get this error

有时,您可能会收到此错误

pg_ctl: another server might be running; trying to start server anyway

So, try running the following command and then run the first command given above.

因此,尝试运行以下命令,然后运行上面给出的第一个命令。

pg_ctl -D /usr/local/var/postgres stop

#1


22  

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

你很可能没电了,你的postgresql服务器没有正确关机。

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

最简单的解决方法是下载官方postgresql应用程序并启动它:它将强制服务器启动(http://postgresapp.com/)

#2


23  

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

运行postgres -D / usr / local / var / postgres你应该看到类似的东西:

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

然后在HINT中运行kill -9 PID

And you should be good to go.

你应该好好去。

#3


11  

Most likely it's because your system shutdown unexpectedly

很可能是因为您的系统意外关闭

Try

尝试

postgres -D /usr/local/var/postgres

You might see

你可能会看到

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

Then try

然后试试

kill -9 PID

example

kill -9 419

And it should start postgres normally

它应该正常开始postgres

#4


9  

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

它可能就像postgresql服务失败一样简单。试试跑步:

sudo service postgresql start

which fixed the issue for me.

这解决了我的问题。

#5


5  

This worked in my case:

这适用于我的情况:

brew uninstall postgresql
rm -fr /usr/local/var/postgres/
brew install postgresql

#6


0  

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".

我经常在Windows上遇到这个问题,我解决问题的方法是服务 - 点击PostgreSQL数据库服务器8.3 - 点击第二个标签“登录” - 选择第一行“本地系统帐户”。

#7


0  

This worked for me: run

这对我有用:跑

sudo lsof -i :<port_number>

sudo lsof -i:

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

之后它将显示当前附加到过程的PID。

After that run sudo kill -9 <PID>

之后运行sudo kill -9

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

如果这不起作用,尝试user8376606提供的解决方案,它肯定会工作!

#8


0  

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

如果要在Linux上重新启动Postgresql,则必须使用以下命令。

/etc/init.d/postgresql restart

/etc/init.d/postgresql重启

#9


0  

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.

这可以是因为意外关闭而没有删除为postgress创建的pid文件。因此,要解决此问题,请删除此pid文件。

  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/

    找到postgres数据目录。在使用自制软件的MAC上,它是/ usr / local / var / postgres /,其他系统可能是/ usr / var / postgres /

  2. Remove pid file

    删除pid文件

    rm postmaster.pid

    rm postmaster.pid

  3. Restart postgress. On Mac,

    重新启动postgress。在Mac上,

    brew services restart postgresql

    brew服务重启postgresql

#10


0  

I resolved the issue via this command

我通过这个命令解决了这个问题

pg_ctl -D /usr/local/var/postgres start

At times, you might get this error

有时,您可能会收到此错误

pg_ctl: another server might be running; trying to start server anyway

So, try running the following command and then run the first command given above.

因此,尝试运行以下命令,然后运行上面给出的第一个命令。

pg_ctl -D /usr/local/var/postgres stop