在 Mac 上启动 postgres 服务器
starting postgres server on Mac
我第三次或第四次遇到这个问题,在重新启动我的 Mac 后(Yosemite 和以前的 OSX 版本一样)postgres 服务器没有启动。我在 this link 之后安装了我的 postgres。知道为什么每次重启后都会出现这种情况吗?
键入 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"?
我刚刚在 mac 上修复了这个问题。我使用自制软件来安装 postgres。这些是我起床和再次 运行 所采取的步骤。
首先查看postgresql服务状态:
pg_ctl -D /usr/local/var/postgres status
如果您看到此 pg_ctl: no server running
,请卸载启动代理:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
然后移动您现有的 postgres 数据(移动而不是删除 - 便宜的保险):
mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
然后初始化你的 postgres 数据库:
initdb /usr/local/var/postgres -E utf8
然后加载您的启动代理:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
或启动它:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
现在再次查看状态:
pg_ctl -D /usr/local/var/postgres status
如果你看到这样的东西,你就可以走了。
pg_ctl: server is running (PID: 61295)
/usr/local/Cellar/postgresql/bin/postgres "-D" "/usr/local/var/postgres"
然后你可以进入你的postgres数据库:
psql -d postgres
之后还需要添加 postgress 角色。
To Resolve missing postgres Role error
要在 mac 上启动 postgres 服务器:
用 brew 安装 postgres
brew install postgres
确保您拥有 /usr/local/postgres
的权限
sudo chown -R `whoami` /usr/local
然后初始化数据库:
initdb /usr/local/var/postgres
launchd
在登录时启动 postgresql:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
加载 postgresql:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
检查您的版本:
psql --version
并访问 postgres
psql -d postgres
我第三次或第四次遇到这个问题,在重新启动我的 Mac 后(Yosemite 和以前的 OSX 版本一样)postgres 服务器没有启动。我在 this link 之后安装了我的 postgres。知道为什么每次重启后都会出现这种情况吗?
键入 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"?
我刚刚在 mac 上修复了这个问题。我使用自制软件来安装 postgres。这些是我起床和再次 运行 所采取的步骤。
首先查看postgresql服务状态:
pg_ctl -D /usr/local/var/postgres status
如果您看到此 pg_ctl: no server running
,请卸载启动代理:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
然后移动您现有的 postgres 数据(移动而不是删除 - 便宜的保险):
mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
然后初始化你的 postgres 数据库:
initdb /usr/local/var/postgres -E utf8
然后加载您的启动代理:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
或启动它:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
现在再次查看状态:
pg_ctl -D /usr/local/var/postgres status
如果你看到这样的东西,你就可以走了。
pg_ctl: server is running (PID: 61295)
/usr/local/Cellar/postgresql/bin/postgres "-D" "/usr/local/var/postgres"
然后你可以进入你的postgres数据库:
psql -d postgres
之后还需要添加 postgress 角色。 To Resolve missing postgres Role error
要在 mac 上启动 postgres 服务器:
用 brew 安装 postgres
brew install postgres
确保您拥有 /usr/local/postgres
的权限sudo chown -R `whoami` /usr/local
然后初始化数据库:
initdb /usr/local/var/postgres
launchd
在登录时启动 postgresql:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
加载 postgresql:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
检查您的版本:
psql --version
并访问 postgres
psql -d postgres