使用Homebrew安装PostgreSQL时出现错误

4

我正在使用 Mac OS X 10.8.5,并尝试使用 Homebrew 安装 PostgreSQL。当我运行 brew info postgresql 时,出现了一些错误和警告,我已经修复了其中的几个。然而,我不知道如何解决其余的问题。

$brew info postgresql

postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 40M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
==> Dependencies
Required: readline 
Recommended: ossp-uuid 
==> Options
--32-bit
    Build 32-bit only
--enable-dtrace
    Build with DTrace support
--no-perl
    Build without Perl support
--no-tcl
    Build without Tcl support
--without-ossp-uuid
    Build without ossp-uuid support
--without-python
    Build without python support
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/issue/2510

To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
  http://www.postgresql.org/docs/9.3/static/upgrading.html

When installing the postgres gem, including ARCHFLAGS is recommended:
  ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To have launchd start postgresql at login:
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
    postgres -D /usr/local/var/postgres

当我运行服务器时,会出现以下信息:

/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `initialize': could not connect to server: No such file or directory (PG::ConnectionBad)
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

我已经卸载了postgresql并重新安装,但似乎我无法删除postgresql 8.x版本。

我阅读了几篇不同的文章来正确安装和运行postgreSQL,并尝试了他们建议的方法,但对我来说似乎都没有起作用。


1
唉,Mac OS X 上的 PostgreSQL 打包情况真是糟糕。在这种情况下,请查找您的 homebrew 安装的 PostgreSQL 的日志文件,并检查它们以查看为什么似乎无法启动。还要检查进程列表(ps -ef | grep postgres)以查看它是否实际上正在运行。 - Craig Ringer
2个回答

2
在Mac OS X El Capitan上使用homebrew安装PostgreSQL
首先,使用以下命令检查'/usr/local'文件夹的所有者。
$ ls -la '/usr'

如果文件的所有者是'root',请运行以下命令将所有者更改为当前登录的用户:

$ sudo chown -R `whoami` /usr/local

使用Homebrew安装PostgreSQL:
$ brew update
$ brew doctor
$ brew install postgresql@15

就是这样!

使用Homebrew卸载PostgreSQL:

$ brew uninstall postgres

然后删除此文件夹:'/usr/local/var/postgres',然后将您本地文件夹的所有者改回为:
$ sudo chown -R root /usr/local

如何操作:
列出brew服务:$ brew services list
运行brew服务:$ brew services start 例如:$ brew services start postgresql
停止brew服务:$ brew services stop 首次登录PostgreSQL:
1.) 运行postgres:$ brew services start postgresql(在这种情况下是postgresql@15)
2.) 使用您的用户名创建数据库:$ createdb `whoami`
3.) 登录到postgres:$ psql 要退出psql,只需键入:\q
4.) 创建数据库(使用终端): $ createdb psql教程:

http://blog.trackets.com/2013/08/19/postgresql-basics-by-example.html http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/

可选,安装pgAdmin:

1.) 下载pdadmin:https://www.pgadmin.org/download/macosx.php

2.) 按住ctrl键点击打开dmg文件,然后将其拖到应用程序文件夹中。再次按住ctrl键点击pdadmin运行它,这样就不会再询问那个烦人的问题了。

登录pgAdmin:

注意:在首次登录时,请使用您安装Postgres时的用户名和密码,然后稍后创建具有权限的新用户,或者只需通过“文件 -> 更改密码...”更改密码。


0
你的Ruby代码显然是链接到系统版本的PostgreSQL,它在/var/pgsql_socket中寻找一个socket。而Homebrew版本则会在/tmp中寻找。(此时,请确保存在类似/tmp/.s.PGSQL.5432的文件。)为了解决这个问题,您可以通过在"host"选项中指定/tmp来告诉您的代码连接到Homebrew版本,只不过您需要正确拼写。
将来,请确保您的Ruby gems与Homebrew版本链接。也许只需卸载并重新安装,并设置正确的路径即可解决问题。

我不明白我需要在这里做什么。希望我在这些领域有更多的知识。所以,如果您能详细说明或列举,我将不胜感激。对此给您带来的麻烦表示抱歉。 - wag0325
这里不清楚你想要做什么。如果文件不存在意味着什么?或者如果它存在呢?这个答案并不是一个答案。 - thatdankent
这个问题本身并不是一个问题。 - Peter Eisentraut

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接