连接到服务器 Postgres 时权限被拒绝



我通过Homebrew安装Postgres9.5.1。但是,我在使用"createdb"创建数据库时遇到问题。最初消息说:"createdb:找不到命令"。然后我卸载并安装自制软件并更新了Postgres。

但是,现在我收到一个新错误:

 createdb: could not connect to database template1: 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"?

我尝试了几件事,例如:

 $rm /usr/local/var/postgres/postmaster.pid

回馈:

"权限被拒绝"

也:

 $postgres -D /usr/local/var/postgres
 postgres cannot access the server configuration file                "/usr/local/var/postgres/postgresql.conf": Permission denied

或:

 $grep unix_socket /usr/local/var/postgres/postgresql.conf
 grep: /usr/local/var/postgres/postgresql.conf: Permission denied
我不知道

该怎么办,我真的不明白发生了什么。谢谢。

在处理了这个问题几天之后,我终于设法通过Homebrew卸载和安装Postgresql并启动服务器来解决它。我是这样做的:

确保 Xcode(适用于 Os X 用户)是最新的

  xcode-select --install

安装自制软件

  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  brew doctor
  brew search
  brew install postgres
  brew update

应该安装Postgres。现在,请确保您具有使用它所需的权限,这是通过允许您的用户此类权限来完成的:

  sudo chown -R :admin /usr/local

权限问题应该得到解决。现在,您(和我一样)可能面临与服务器相关的问题。

     psql -U postgres -p 5432 -h localhost

这将解决问题:

     launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
     mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
     initdb /usr/local/var/postgres -E utf8
     launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

     rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

现在,您可以使用以下命令启动数据库服务器:

pg_ctl -D /usr/local/var/postgres -l logfile start

不要忘记使此命令行适应您的特定情况和地址。

祝你好运

最新更新