由于缺less服务器configuration文件,Postgres无法从狮子开始

我试图设置一个相对干净的狮子安装PG,它不是成功的。

首先,我成功安装了自制软件,并安装了postgresql,没有任何错误。

然后我试图运行一个rails应用程序,得到一个错误。 试过运行这个脚本: http : //nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

为了隐藏默认的系统postgres安装,但现在我收到以下错误:

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

当我尝试在bin目录中运行postgres脚本时,出现以下错误:

 larson:~ larson$ /usr/local/Cellar/postgresql/9.1.3/bin/postgres ; exit; postgres does not know where to find the server configuration file. You must specify the --config-file or -D invocation option or set the PGDATA environment variable. logout 

很明显,postgres无法启动,因为它没有正确configuration。 有没有人有正确的方式来configuration它,所以它的启动?

盲目地运行自制脚本,不知道自己在做什么并不能解决问题 – 它创造了它们。 结束Rant。

我们不知道你之前有什么错误,但现在你显然没有configuration数据库集群。

您需要正确设置您的Postgres集群(请参阅Postgres手册 ),并且/或者在启动时告诉postgres数据库集群在哪里(这就是You must specify the --config-file or -D invocation option or set the PGDATA environment variable.从错误消息中You must specify the --config-file or -D invocation option or set the PGDATA environment variable. )。 手册17.3节谈到这一点。

运行brew info postgres为您提供了基本知识。 例如:

如果这是您的第一次安装,请创build一个数据库:

 initdb /usr/local/var/postgres -E utf8 

或者重新启动数据库服务器:

 launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 

关于这个自制问题的讨论: https : //github.com/Homebrew/homebrew/issues/21920

你可能只需要这样做:

 export PGDATA=/usr/local/var/postgres 

只要检查一下,看到目录确实在那里,并有postgresconfiguration文件。

你运行initdb吗? 我发现这个问题与postgres 9.1.3的默认安装。 看起来initdb使用config构build数据库目录。

这包含在brew安装附带的说明中。
试试brew postgresql并阅读“新安装”