简体   繁体   English

Postgres.app 无法在端口 5432 上启动

[英]Postgres.app Could not start on port 5432

I'm using http://postgresapp.com .我正在使用http://postgresapp.com In the menubar it gives the error " Could not start on port 5432."在菜单栏中,它给出了错误“无法在端口 5432 上启动”。 Similarly if I try to start the server from the terminal, I get:同样,如果我尝试从终端启动服务器,我会得到:

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 startpg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start了输出server starting但在连接到 psql 时仍然出现相同的错误。

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,它应该会成功启动。

You can stop the process by finding the PID with您可以通过查找 PID 来停止该过程

lsof -i :5432

and then killing it with然后用它杀死它

kill -9 <PID>

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

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

Using a hint from Frank Wiles I ran ps auxw | grep post使用Frank Wiles的提示,我运行了ps auxw | grep post 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: 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.所以我通过 .bash_profile 编辑以导出该目录。 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.当我运行echo $PATH我可以看到 usr/bin 是路径中的第一件事,而which psql仍然给出了/usr/bin路径。 At that point a friend guided me in the right direction:那时,一位朋友引导我走向正确的方向:

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.启动一个新的终端窗口,然后运行which psql它应该指向 postgres.app 位置,并且 psql 应该启动 postgres shell。 Works fine now.现在工作正常。

You my have another instance of postgres running, that is the only application interested in this port.您有另一个 postgres 实例正在运行,这是唯一对此端口感兴趣的应用程序。 You should use netstat and ps to determine this.您应该使用 netstat 和 ps 来确定这一点。 Then stop the instance and uninstall it, you mayhave installed enterpiseDb for example, that is what I did.然后停止实例并卸载它,例如您可能安装了enterpiseDb,这就是我所做的。

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.对我来说,它总是在我的 MacBook 电池没电时发生,即使电脑已经进入睡眠状态。 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.我在~/Library/Application\\ Support/Postgres/var-9.4闲逛,发现了另一个我以前从未见过的postmaster.pid文件。 I deleted it, and now everything is back up and running!我删除了它,现在一切都恢复正常了! I am running the Postgres.app version, not the brew version.我正在运行 Postgres.app 版本,而不是 brew 版本。

Steps I took:我采取的步骤:

  1. Make sure postgres.app is not running.确保postgres.app没有运行。
  2. Run rm ~/Library/Application\\ Support/Postgres/var-9.$X/postmaster.pid运行rm ~/Library/Application\\ Support/Postgres/var-9.$X/postmaster.pid
  3. If you don't have a var-9.$X directory, just run rm ~/Library/Application\\ Support/Postgres/postmaster.pid如果您没有var-9.$X目录,只需运行rm ~/Library/Application\\ Support/Postgres/postmaster.pid
  4. Restart postgres.app重启postgres.app
  5. Get back to developing cool stuff.回去开发很酷的东西。

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 上的所有问题。

I generally face this issue on my mac, and this fixes it for me always我通常在我的 mac 上遇到这个问题,这总是为我修复它

rm /usr/local/var/postgres/postmaster.pid
brew services restart postgresql

Hope this is helpful希望这有帮助

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.我不知道为什么,但即使我退出应用程序并检查没有使用 ps -a 运行 postgres 进程。 these files existed:这些文件存在:

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

It can also happen that the PID is taken. PID 也可能被占用。 This ocurred to me when the Computer suffered an unexpected reboot.当计算机意外重启时,我发生了这种情况。

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.服务器立即启动。

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 $ lsof -i | grep LISTEN again just to make sure.再次$ lsof -i | grep LISTEN只是为了确保。 Saw no postgres running anywhere and was able to open the Postgres app without getting that warning.没有看到任何地方运行 postgres,并且能够在没有收到警告的情况下打开 Postgres 应用程序。

Then I reinstalled postgres with $ brew install postgres然后我用$ brew install 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.现在一切正常。

This is what worked for me: $ sudo pkill -u postgres这对我有用:$ sudo pkill -u postgres

Props to this resource: https://github.com/PostgresApp/PostgresApp/issues/197#issuecomment-474534056此资源的道具: https : //github.com/PostgresApp/PostgresApp/issues/197#issuecomment-474534056

At a guess, something else had taken port 5432 so the app chose to run on 5433 instead.猜测是其他东西占用了端口 5432,因此应用程序选择在 5433 上运行。

Why not just connect to Pg on port 5433, if that's where it's running?如果它正在运行,为什么不直接连接到端口 5433 上的 Pg? You have a /tmp/.s.PGSQL.5432 socket file, so you can connect with psql -p 5433 for UNIX domain socket connections.您有一个/tmp/.s.PGSQL.5432套接字文件,因此您可以使用psql -p 5433进行连接以进行 UNIX 域套接字连接。 It'll also be listening on the same port with TCP/IP, so you can use psql -h localhost -p 5433 for TCP/IP and have your apps connect to port 5433 instead of 5432.它还将在与 TCP/IP 相同的端口上侦听,因此您可以对 TCP/IP 使用psql -h localhost -p 5433并使您的应用程序连接到端口 5433 而不是 5432。

Change your .psqlrc to set the new port as default and you can forget it isn't on the default port.更改您的.psqlrc以将新端口设置为默认端口,您可能会忘记它不在默认端口上。

I had similar problem when trying to use postgresql with rails.我在尝试将 postgresql 与 rails 一起使用时遇到了类似的问题。 Updating my Gemfile to use new version of gem pg solve this problem for me.更新我的 Gemfile 以使用新版本的 gem pg 为我解决了这个问题。 (gem pg version 0.16.0 works). (gem pg 0.16.0 版有效)。 In the Gemfile use:在 Gemfile 中使用:

gem 'pg', '0.16.0'

then run the following to update the gem然后运行以下命令来更新 gem

bundle install --without production
bundle update
bundle install

Mine failed to start up suddenly, and when I checked Console.app I saw:我的突然启动失败,当我检查 Console.app 时,我看到:

com.heroku.postgres-service: 
FATAL:  could not create shared memory segment: Cannot allocate memory
DETAIL:  Failed system call was shmget(key=5432001, size=3874816, 03600).
HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter.  You can either reduce the request size or reconfigure the kernel with larger SHMALL.  To reduce the request size (currently 3874816 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
The PostgreSQL documentation contains more information about shared memory configuration.

It turns out Postgres wouldn't start up because I had Wireshark (and X11) running.结果证明 Postgres 无法启动,因为我运行了 Wireshark(和 X11)。 It worked fine after I quit Wireshark.在我退出 Wireshark 后,它运行良好。

Good luck!祝你好运!

I resolved this problem by我解决了这个问题

  1. Identifying what was running on port 5432 by using "netstat" in the CL, which was postgreSQL not Postgres通过在 CL 中使用“netstat”来识别端口 5432 上运行的内容,这是 postgreSQL 而不是 Postgres
  2. I located the directory that contained postgreSQL, which was root/Library/PostgreSQL我找到了包含 postgreSQL 的目录,即 root/Library/PostgreSQL
  3. I ensured an instants of the application wasn't running via Activity Monitor我确保应用程序的瞬间没有通过活动监视器运行
  4. Then I deleted the folder and rebooted!然后我删除了文件夹并重新启动! Everything was fine!一切都很好!

Somehow I totally forgot that this socket file will be hidden because of the dot.不知何故,我完全忘记了这个套接字文件会因为点而被隐藏。 Make sure you use ls -A /tmp/.s.PGSQL.5432 if you are checking to see if the socket is actually there.如果要检查套接字是否确实存在,请确保使用ls -A /tmp/.s.PGSQL.5432

You most likely has a PostgreSQL installed, deleted it and installed it again.您很可能安装了 PostgreSQL,将其删除并重新安装。 PostgreSQL typically used port 5432 but if not available, increases to the next available one, in this case 5433. So, you probably chose this port on your second install. PostgreSQL 通常使用端口 5432,但如果不可用,则增加到下一个可用端口,在本例中为 5433。因此,您可能在第二次安装时选择了此端口。

I think you should check file:我认为你应该检查文件:

/etc/services /etc/服务

and adjust rows below for your expected port number:并根据您的预期端口号调整以下行:

postgresql 5432/udp # PostgreSQL Database postgresql 5432/udp # PostgreSQL 数据库

postgresql 5432/tcp # PostgreSQL Database postgresql 5432/tcp # PostgreSQL 数据库

After this you should restart your computer (simplest way).在此之后,您应该重新启动计算机(最简单的方法)。

I had the same issues:我有同样的问题:

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

In my case it was a corrupt host file on my mac.就我而言,它是我 mac 上的一个损坏的主机文件。 I was missing:我失踪了:

127.0.0.1   localhost

A quick easy way to check is to open terminal and type:一种快速简单的检查方法是打开终端并输入:

ping localhost

or:或者:

scutil -r localhost

More info here Hope it helps.更多信息在这里希望它有帮助。

Netstat, ps aux, etc ... none showed 5432 in use. Netstat、ps aux 等...没有显示 5432 正在使用中。 Checked /Library.检查/库。 Found PG9.6 old install still there.发现 PG9.6 旧安装仍然存在。 Did rm -rf and bang.做了 rm -rf 和 bang。 Version 11 works fine.版本 11 工作正常。

I was losing my mind over this problem!我对这个问题失去了理智! i kept running我一直在跑

lsof -i | lsof -i | grep 5432格雷普 5432

and nothing was showing up!什么都没有出现! finally i ran it using sudo and a potgres client showed up.最后我使用 sudo 运行它,一个potgres客户端出现了。 so if anyone else has tried the lsof and went nowhere, try it with sudo.因此,如果其他人尝试过 lsof 却无处可去,请尝试使用 sudo。

sudo lsof -i |须藤 lsof -i | grep 5432格雷普 5432

and then然后

sudo kill <the_pid_from_postgresql_found_from_lsof>须藤杀死 <the_pid_from_postgresql_found_from_lsof>

The same problem just happened to me.同样的问题刚刚发生在我身上。 I had Postgres.app 9.2.4.1 running since a while.我有一段时间运行 Postgres.app 9.2.4.1。 When I updated Mac OS X to 10.8.5, after the mandatory reboot it was not working anymore.当我将 Mac OS X 更新到 10.8.5 时,强制重启后它不再工作了。 I tried several things, including updating to 9.2.4.3 and neither after another reboot it was working.我尝试了几件事,包括更新到 9.2.4.3 并且在再次重新启动后它都没有工作。

I had to open the file /Users/$USER/Library/Application Support/Postgres/var/postgresql.conf and to:我必须打开文件/Users/$USER/Library/Application Support/Postgres/var/postgresql.conf并:

  1. uncomment line unix_socket_permissions = 0777取消注释行unix_socket_permissions = 0777
  2. uncomment and adapt line unix_socket_directory = '/tmp'取消注释并调整行unix_socket_directory = '/tmp'

After a restart, Postgres.app was running like a charm.重新启动后,Postgres.app 就像一个魅力一样运行。

A file named "postmaster.pid" (in my $PGDATA directory) were preventing postgresql to start.名为“postmaster.pid”的文件(在我的 $PGDATA 目录中)阻止 postgresql 启动。 It was a zombie file, placed there 10 days ago and when I brutally shut down the computer (pulling the plug, literally), no clean up process had the opportunity to remove that file.这是一个僵尸文件,10 天前放置在那里,当我粗暴地关闭计算机(拔掉插头,字面意思)时,没有任何清理过程有机会删除该文件。

除了所有有用的答案,您可能还想查看官方页面说明: postgressapp.com/documentation/remove.html

For me, I had DBeaver open and it was holding onto the connection. 对我来说,我打开了DBeaver,它一直保持连接。 Quitting that app allowed postgresql.app to start the databases 退出该应用程序允许postgresql.app启动数据库

I had this same issue and mine was caused by some configuration issues I was having.我有同样的问题,我的问题是由我遇到的一些配置问题引起的。 Clearing the user configurations and reinstalling postgres in brew worked for me!清除用户配置并在 brew 中重新安装 postgres 对我有用!

 brew uninstall postgresql rm -rf /usr/local/var/postgres

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM