PostgreSQL 服务器不会停止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17930167/
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
PostgreSQL server won't stop
提问by Parker Hutchinson
Having a bit of an issue with PostgreSQL on Mac OS X 10.8.4. I accidentally did brew rm postgresql --force
while the postgres server was running. When I installed using brew install postgresql
and ran pg_ctl -D /usr/local/var/postgres start
I get:
Mac OS X 10.8.4 上的 PostgreSQL 有点问题。我brew rm postgresql --force
在 postgres 服务器运行时不小心做了。当我安装 usingbrew install postgresql
并运行时,pg_ctl -D /usr/local/var/postgres start
我得到:
pg_ctl: another server might be running; trying to start server anyway
server starting
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 752) running in data directory "/usr/local/var/postgres"?
when I run "ps -ef | grep postgres" I get:
当我运行“ps -ef | grep postgres”时,我得到:
501 752 235 0 12:42PM ?? 0:00.01 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
501 754 752 0 12:42PM ?? 0:00.00 postgres: checkpointer process
501 755 752 0 12:42PM ?? 0:00.34 postgres: writer process
501 756 752 0 12:42PM ?? 0:00.02 postgres: wal writer process
501 757 752 0 12:42PM ?? 0:00.01 postgres: autovacuum launcher process
501 758 752 0 12:42PM ?? 0:00.01 postgres: stats collector process
501 945 452 0 12:58PM ttys000 0:00.00 grep postgres
when I try to stop the server with pg_ctl stop -D /usr/local/var/postgres -m fast
or pg_ctl -D /usr/local/var/postgres stop -mi
I get:
当我尝试停止服务器时,pg_ctl stop -D /usr/local/var/postgres -m fast
或者pg_ctl -D /usr/local/var/postgres stop -mi
我得到:
waiting for server to shut down........................................... Failed
pg_ctl: server does not shut down
EDIT
编辑
which pg_ctl
/usr/local/bin/pg_ctl
pg_ctl --version
pg_ctl (PostgreSQL) 9.2.4
Gist of server.log
: https://gist.github.com/anonymous/6106182
要点server.log
:https: //gist.github.com/anonymous/6106182
采纳答案by Parker Hutchinson
turns out that my brew.plist for postgres needed to be unloaded and removed at ~/Library/LaunchAgents/ . After a restart all is well... closing question.
事实证明,我的 postgres brew.plist 需要在 ~/Library/LaunchAgents/ 卸载和删除。重新启动后一切都很好......结束问题。
回答by Neara
Had same issue, pg_ctl: server does not shut down
. Furthermore, ps auxwww | grep postgres
showed no postgres running, while pg_ctl -D /usr/local/var/postgres status
showed that postgres is running. Restarting my mac didn't help, i even went as far as to reset SMC, but this SO Q/A gave me an idea what to look for next: brew issues.
有同样的问题,pg_ctl: server does not shut down
。此外,ps auxwww | grep postgres
显示没有运行 postgres,而pg_ctl -D /usr/local/var/postgres status
显示 postgres 正在运行。重新启动我的 mac 没有帮助,我什至重置了 SMC,但是这个 Q/A 让我知道接下来要寻找什么:酿造问题。
Following this line of thought, i found this helpful blog post, that came down to following commands that solved this issue for me:
按照这个思路,我发现了这篇有用的博客文章,归结为以下命令为我解决了这个问题:
$ brew services list
$ brew services restart postgresql
Hope this will help someone.
希望这会帮助某人。
Update - Unknown command: services
更新 - 未知命令:服务
After a bit of investigation following one of the comments ('Unknown command: services'), i found out that the authors of Homebrew decided to remove services
from the repo, seeing as no one wants to maintain this code.
在对其中一条评论(“未知命令:服务”)进行了一些调查之后,我发现 Homebrew 的作者决定services
从 repo 中删除,因为没有人愿意维护此代码。
You can read more about it hereand here(related github tickets).
您可以在此处和此处阅读有关它的更多信息(相关的 github 票证)。
After some more digging, I found thisrepo that adds services
on macs.
经过更多的挖掘,我发现了这个services
在 macs上添加的 repo 。
This is how I 'returned' services
:
这就是我“返回”的方式services
:
~ ? brew tap gapple/services
~ ? brew services
usage: [sudo] brew services [--help] <command> [<formula>]
Small wrapper around `launchctl` for supported formulae, commands available:
cleanup Get rid of stale services and unused plists
list List all services managed by `brew services`
restart Gracefully restart selected service
start Start selected service
stop Stop selected service
Options, sudo and paths:
sudo When run as root, operates on /Library/LaunchDaemons (run at boot!)
Run at boot: /Library/LaunchDaemons
Run at login: /Users/user/Library/LaunchAgents
Here is another suggested solution: https://apple.stackexchange.com/questions/150300/need-help-using-homebrew-services-command. Didn't check it myself, so don't know if and how it works.
这是另一个建议的解决方案:https: //apple.stackexchange.com/questions/150300/need-help-using-homebrew-services-command。没有自己检查过,所以不知道它是否以及如何工作。
回答by rust
$ brew services list
$ brew services list
$ brew services stop postgresql
$ brew services stop postgresql
Stopping postgresql
, but it might take a while
→ Successfully stopped postgresql
(label: homebrew.mxcl.postgresql)
正在停止postgresql
,但可能需要一段时间 → 已成功停止postgresql
(标签:homebrew.mxcl.postgresql)
回答by Max Bentata
I was having the same problem...removing the launch agent solved the problem for me:
我遇到了同样的问题......删除启动代理为我解决了这个问题:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
回答by user3155603
I had a similar issue. I had forgot that I integrated 'lunchy' a few days ago and was using
it as a launchctl wrapper to initiate plist ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
on start up. pg_ctl was not effective because of the following line of code <key>KeepAlive<key>
:
我有一个类似的问题。我忘记了几天前我集成了“午餐”,并将其用作 launchctl 包装器以~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
在启动时启动 plist 。由于以下代码行,pg_ctl 无效<key>KeepAlive<key>
:
<?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3 <plist version="1.0">
4 <dict>
5 <key>KeepAlive</key>
6 <true/>
7 <key>Label</key>
8 <string>homebrew.mxcl.postgresql</string>
9 <key>ProgramArguments</key>
10 <array>
11 <string>/usr/local/opt/postgresql/bin/postgres</string>
12 <string>-D</string>
13 <string>/usr/local/var/postgres</string>
14 <string>-r</string>
15 <string>/usr/local/var/postgres/server.log</string>
16 </array>
17 <key>RunAtLoad</key>
18 <true/>
19 <key>WorkingDirectory</key>
20 <string>/usr/local</string>
21 <key>StandardErrorPath</key>
22 <string>/usr/local/var/postgres/server.log</string>
23 </dict>
24 </plist>
Trying to kill the process directly didn't work because I needed to unload the plist.
尝试直接终止进程不起作用,因为我需要卸载 plist。
launchctl unload homebrew.mxcl.postgresql.plist
回答by Elliott Harrison
I got round this error by using the command
我通过使用命令解决了这个错误
pg_ctl stop -m immediate
pg_ctl start
I did not need to unload the plist this way.
我不需要以这种方式卸载 plist。
回答by Peter Lustig
When relying on brew-installed PostgreSQL, the following command worked for shutting it down.
当依赖 brew 安装的 PostgreSQL 时,以下命令可以关闭它。
> brew services stop postgresql
stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
As mentioned in another answer grepping through the list of processes and then killing anything postgres-related does notwork.
作为另一个答案通过进程列表grepping提到的,然后杀死任何Postgres的相关并没有工作。
ps aux | grep postgres
kill $PID
回答by M3RS
I didn't have postgres
started via brew services
, so couldn't stop it that way.
我没有postgres
通过 开始brew services
,所以无法以这种方式停止。
This worked.
这奏效了。
$ ps -ef | grep postgres
501 547 1 0 2:07pm ?? 0:00.29 /Applications/Postgres.app/Contents/Versions/9.6/bin/postgres -D /Users/username/Library/Application Support/Postgres/var-9.6 -p 5432
Use -D
paramater from above.
使用-D
上面的参数。
$ pg_ctl stop -D "/Users/username/Library/Application Support/Postgres/var-9.6"