postgresql Postgres.app 无法在端口 5432 上启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12028037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres.app Could not start on port 5432
提问by Chris
I'm using http://postgresapp.com. In the menubar it gives the error " Could not start on port 5432." Similarly if I try to start the server from the terminal, I get:
我正在使用http://postgresapp.com。在菜单栏中,它给出了错误“无法在端口 5432 上启动”。同样,如果我尝试从终端启动服务器,我会得到:
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"?
I also ran pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
and got the output server starting
but still get the same errors when connecting to psql.
我也运行pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
并获得了输出,server starting
但在连接到 psql 时仍然出现相同的错误。
采纳答案by Paul McLachlan
You my have another instance of postgres running, that is the only application interested in this port. You should use netstat and ps to determine this. Then stop the instance and uninstall it, you mayhave installed enterpiseDb for example, that is what I did.
您有另一个 postgres 实例正在运行,这是唯一对此端口感兴趣的应用程序。您应该使用 netstat 和 ps 来确定这一点。然后停止实例并卸载它,例如您可能安装了enterpiseDb,这就是我所做的。
回答by Max von Hippel
If you are running your server on a macOS machine and installed Postgres through Homebrew, you can stop the current instance like this:
如果你在 macOS 机器上运行你的服务器并通过 Homebrew 安装了 Postgres,你可以像这样停止当前实例:
brew services stop postgresql
brew 服务停止 postgresql
Then click the Elephant in the native menu-bar at the top of the screen and it should successfully startup.
然后单击屏幕顶部本机菜单栏中的 Elephant,它应该会成功启动。
回答by Некто
You can stop the process by finding the PID with
您可以通过查找 PID 来停止该过程
lsof -i :5432
and then killing it with
然后用它杀死它
kill -9 <PID>
回答by eezis
I was just having this exact issue. When I ran which psql
it was pointing at the Postgres client tools installed with Lion:
我只是有这个确切的问题。当我运行时,which psql
它指向与 Lion 一起安装的 Postgres 客户端工具:
/usr/bin/psql
/usr/bin/psql
Using a hint from Frank WilesI ran ps auxw | grep post
to confirm that postgres was running and that it was running on the right port, that also showed me the postgres.app path:
使用Frank Wiles的提示,我运行ps auxw | grep post
以确认 postgres 正在运行并且它在正确的端口上运行,这也向我显示了 postgres.app 路径:
/Applications/Postgres.app/Contents/MacOS/bin/postgres
.
/Applications/Postgres.app/Contents/MacOS/bin/postgres
.
So I edited by .bash_profile to export that directory. On first effort I added it to the end of the path. When I ran echo $PATH
I could see that usr/bin was the first thing in the path, and which psql
still gave the /usr/bin
path. At that point a friend guided me in the right direction:
所以我通过 .bash_profile 编辑以导出该目录。首先,我将它添加到路径的末尾。当我运行时,echo $PATH
我可以看到 usr/bin 是路径中的第一件事,并且which psql
仍然给出了/usr/bin
路径。那时,一位朋友引导我走向正确的方向:
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:${PATH}"
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:${PATH}"
Start a new terminal window, then run which psql
-- it should point to the postgres.app location and psql should fire up the postgres shell. Works fine now.
启动一个新的终端窗口,然后运行which psql
——它应该指向 postgres.app 位置并且 psql 应该启动 postgres shell。现在工作正常。
回答by Jamon Holmgren
If you've installed Postgres via another method (for example, from www.postgresql.org) and it's starting automatically at startup, you can prevent that Postgres from starting via the following:
如果您通过其他方法(例如,从 www.postgresql.org)安装了 Postgres 并且它在启动时自动启动,您可以通过以下方式阻止 Postgres 启动:
sudo launchctl unload /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist
sudo rm -f /Library/LaunchDaemons/com.edb.launchd.postgresql-X.X.plist
TIP: use tab to autocomplete after the com.edb.launchd
part to figure out what version is loading.
提示:在com.edb.launchd
部分之后使用选项卡自动完成以找出正在加载的版本。
Restart Postgres.app and you should be good to go.
重启 Postgres.app 就可以了。
(from http://forums.enterprisedb.com/posts/list/1831.page;jsessionid=70621DC48C99EDE663A6A594B05F1A02#6782)
(来自http://forums.enterprisedb.com/posts/list/1831.page;jsessionid=70621DC48C99EDE663A6A594B05F1A02#6782)
回答by Daniel Bonnell
I have tried just about every solution to this problem that is out there. For me it always happens when my MacBook's battery dies, even if the computer is already sleeping. I was poking around in ~/Library/Application\ Support/Postgres/var-9.4
and I discovered another postmaster.pid
file that I had not seen before. I deleted it, and now everything is back up and running! I am running the Postgres.app version, not the brew version.
我已经尝试了几乎所有解决这个问题的方法。对我来说,它总是在我的 MacBook 电池没电时发生,即使电脑已经进入睡眠状态。我在四处探查,~/Library/Application\ Support/Postgres/var-9.4
发现了另一个postmaster.pid
我以前从未见过的文件。我删除了它,现在一切都恢复正常了!我正在运行 Postgres.app 版本,而不是 brew 版本。
Steps I took:
我采取的步骤:
- Make sure
postgres.app
is not running. - Run
rm ~/Library/Application\ Support/Postgres/var-9.$X/postmaster.pid
- If you don't have a
var-9.$X
directory, just runrm ~/Library/Application\ Support/Postgres/postmaster.pid
- Restart
postgres.app
- Get back to developing cool stuff.
- 确保
postgres.app
没有运行。 - 跑
rm ~/Library/Application\ Support/Postgres/var-9.$X/postmaster.pid
- 如果你没有
var-9.$X
目录,只需运行rm ~/Library/Application\ Support/Postgres/postmaster.pid
- 重新开始
postgres.app
- 回去开发很酷的东西。
回答by Aaron Becker
This command is a one-liner that instantly kills all PostgresSQL processes.
此命令是单行命令,可立即终止所有 PostgresSQL 进程。
sudo kill -kill $(sudo lsof -t -i :5432)
This fixed all my problems on Mac OSX Mojave 10.14.1.
这解决了我在 Mac OSX Mojave 10.14.1 上的所有问题。
回答by ksnabb
I had a similar problem where I could not connect to the Postgres.app even though the app itself said that it is running on port 5432.
我遇到了类似的问题,即使应用程序本身说它在端口 5432 上运行,我也无法连接到 Postgres.app。
I am not sure why, but even when I quit the app and checked that no postgres processes was running with ps -a. these files existed:
我不知道为什么,但即使我退出应用程序并检查没有使用 ps -a 运行 postgres 进程。这些文件存在:
/tmp/.s.PGSQL.5432
and
和
/tmp/.s.PGSQL.5432.lock
My solution was to delete these files and then start the postgres.app again.
我的解决方案是删除这些文件,然后再次启动 postgres.app。
回答by Lomefin
It can also happen that the PID is taken. This ocurred to me when the Computer suffered an unexpected reboot.
PID 也可能被占用。当计算机意外重启时,我发生了这种情况。
If so, you must go to:
如果是这样,你必须去:
?/Library/Application Support/Postgres/var-9.4
You can check that path in Postgres.app Preferences dialog.
您可以在 Postgres.app 首选项对话框中检查该路径。
And then, just remove the pid file
然后,只需删除pid文件
sudo rm postmaster.pid
And the server starts up right away.
服务器立即启动。
回答by AdjunctProfessorFalcon
When trying to open the Postgres app was getting that same error regarding post 5432 (on Mac OSX 10.10.5)
当尝试打开 Postgres 应用程序时,遇到关于 post 5432 的相同错误(在 Mac OSX 10.10.5 上)
I did:
我做了:
$ lsof -i | grep LISTEN
Saw which PID was running postgres at that port, did:
$ killall {pid}
and then $ brew uninstall postgres
看到哪个 PID 在那个端口运行 postgres,做了:
$ killall {pid}
然后$ brew uninstall postgres
After that, restarted my Mac, and ran:
之后,重新启动我的 Mac,然后运行:
$ lsof -i | grep LISTEN
again just to make sure. Saw no postgres running anywhere and was able to open the Postgres app without getting that warning.
$ lsof -i | grep LISTEN
再次只是为了确保。没有看到任何地方运行 postgres,并且能够在没有收到警告的情况下打开 Postgres 应用程序。
Then I reinstalled postgres with $ brew install postgres
然后我重新安装了 postgres $ brew install postgres
ANOTHER OPTION:
另一种选择:
(I also tried this one time when the above approach didn't work and I could not kill any of the PID)
(当上述方法不起作用并且我无法杀死任何PID时,我也尝试过一次)
$ ps auxw | grep post
Saw a slew postgres processes, which I then sudo kill <PID>
看到了大量的 postgres 进程,然后我 sudo kill <PID>
Everything working fine now.
现在一切正常。