Postgresql.app vs Homebrew



我是RoR的新手,我希望将我的下一个应用程序部署到heroku。我想要我的发展&测试环境,以匹配我的生产环境,实现最平稳的过渡。因此,我开始在我的系统上安装postgresql。这个过程非常令人沮丧,我非常困惑。我遵循了无数的教程,但都无济于事,似乎很多教程都有相互矛盾的信息。以下是我所知道的:

有很多方法可以安装postgresql。常见的选项有macports、homebrew、fink、Postgresql.app或enterpriseDB。一旦你安装了之前的一个,你必须创建你的rails应用程序,然后运行:

rails new <app_name> -d postgresql

或者运行标准的rails-new,然后在gemfile中将sqlite3更改为pg。然后,如果我是正确的,您实际上必须通过以下操作在命令行中创建自己的数据库:

$ psql
$ CREATE DATABASE your_database_name;

然后,编辑您的database.yml以遵循以下内容:

development:
  adapter: postgresql
  encoding: unicode
  database: <your_database_name>
  host: localhost
  pool: 5
  username: <username>
  password:

一旦完成,一切都会好起来。然而,我遇到了一些问题。事实上,我使用上面的过程让它工作,但我对它是如何运行感到困惑。在几个小时的努力中,我安装了macports、homebrew和postgresql.app。然而,每当我试图在没有运行postgresql.app的情况下与数据库交互(例如"rake db:migrate")时,我都会收到以下错误:

could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (fe80::1) and accepting
    TCP/IP connections on port 5432?

如果我把它放回去,一切都好。好的,这让我假设我的系统正在使用postgresql.app来运行postresql。有了这些信息,我自信地卸载了postgresql的macports和hombrew安装。然而,在这样做的时候,我在尝试与数据库交互时遇到了这个错误:

Library not loaded: /usr/local/lib/libpq.5.4.dylib (LoadError)

我重新安装了macports,但仍然出现同样的错误。然后我重新安装自制软件,错误就消失了。然后我再次卸载macports,一切都很好。似乎postgresql.app和我的自制软件安装在某种程度上是相互依赖的。如果我是正确的,它们应该能够彼此独立运行,因为每个都是postgreql的完整安装。在这一点上,我几乎没有什么想法。关于如何完成这一过程以及正在发生的事情的任何和所有输入都将非常感谢。

编辑

$ which psql

显示:

/usr/local/bin/psql

ls -l /usr/local/bin/psql

显示:

lrwxr-xr-x  1 robertquinn  admin  35 Jul 29 17:32 /usr/local/bin/psql -> ../Cellar/postgresql/9.1.4/bin/psql 

自制啤酒绝对是一条不错的选择。在使用Macports多年后,我发现Homebrew更易于使用、升级和维护。

如果你是Homebrew的新手,有时当你安装一些东西时,会在安装结束时打印输出,这会给你额外的任务。有时安装会要求您手动创建新的链接,有时它会要求您使用位于地窖中的新可执行文件重做链接。请确保阅读该输出并遵循安装后的说明。

按照这些说明操作后,打开一个新的终端窗口以确保您的设置得到遵守。

此外,如果您使用rails new app_name -D postgresql,那么您的database.yml文件应该已经正确配置,当然,除非您已经将postgres实例配置为使用用户名和密码。

为了使启动和停止postgres更容易,我将这些命令添加到我的.profile文件中

# postgres
alias pg_start="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start"
alias pg_stop="pg_ctl -D /usr/local/var/postgres stop -s -m fast"

最新更新