postgresql 在 Mac 上启动 postgres 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28248737/
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
starting postgres server on Mac
提问by user2066049
I am having this issue third or forth time where after restarting my Mac (Yosemite and same thing with previous OSX version) postgres server doesn't start. I had installed my postgres following thislink. Any idea why this consistently occurs after every restart?
我第三次或第四次遇到这个问题,在重新启动我的 Mac(优胜美地和以前的 OSX 版本相同的东西)后,postgres 服务器没有启动。我已经按照这个链接安装了我的 postgres 。知道为什么每次重启后都会发生这种情况吗?
typing psql
it gives
输入psql
它给出
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"?
回答by m79lkm
I just fixed this on my mac. I used homebrew to install postgres. These are the steps I took to get up and running again.
我刚刚在我的 mac 上修复了这个问题。我使用自制软件来安装 postgres。这些是我重新启动和运行所采取的步骤。
First check the status of the postgresql service:
首先检查postgresql服务的状态:
pg_ctl -D /usr/local/var/postgres status
if you see this pg_ctl: no server running
, unload the launch agent:
如果你看到这个pg_ctl: no server running
,卸载启动代理:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
then move your existing postgres data (move rather than delete - cheap insurance):
然后移动您现有的 postgres 数据(移动而不是删除 - 廉价保险):
mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
then initialize your postgres database:
然后初始化你的 postgres 数据库:
initdb /usr/local/var/postgres -E utf8
then load your launch agent:
然后加载您的启动代理:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
OR start it:
或启动它:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Now check the status again:
现在再次检查状态:
pg_ctl -D /usr/local/var/postgres status
if you see something like this, you are good to go.
如果你看到这样的东西,你就可以走了。
pg_ctl: server is running (PID: 61295)
/usr/local/Cellar/postgresql/bin/postgres "-D" "/usr/local/var/postgres"
Then you can go into your postgres database:
然后你可以进入你的 postgres 数据库:
psql -d postgres
回答by svnm
To start postgres server on mac:
在 Mac 上启动 postgres 服务器:
install postgres with brew
用 brew 安装 postgres
brew install postgres
ensure you have permissions for /usr/local/postgres
确保您拥有/usr/local/postgres 的权限
sudo chown -R `whoami` /usr/local
then init the db:
然后初始化数据库:
initdb /usr/local/var/postgres
initdb /usr/local/var/postgres
To have launchd
start postgresql at login:
要launchd
在登录时启动 postgresql:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
To load postgresql:
加载 postgresql:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
To check your version:
要检查您的版本:
psql --version
psql --version
And to access postgres
并访问 postgres
psql -d postgres
psql -d postgres