ruby-on-rails - 如何指定 rails 使用哪个 postgres 副本

标签 ruby-on-rails postgresql ruby-on-rails-4 version puma

如何指定 postgres rails 使用的版本?当我运行 puma 并转到 localhost:3000 时出现错误

PG::ConnectionBad
fe_sendauth: no password supplied

我认为正在使用的副本可能是手动安装 9.3,就像我运行时一样:

/usr/local/Cellar/postgresql/9.4.1/bin/pg_ctl -D /usr/local/var/postgres start

我得到错误:

stgres start
server starting
LOG:  skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.1.

我在我的系统上找到了三个 pg_hba.conf 副本:

/Library/PostgreSQL/9.3/data/pg_hba.conf
/Users/lasernite/Library/Application Support/Postgres/var-9.4/pg_hba.conf
/usr/local/var/postgres/pg_hba.conf

我相信第一个来自某个时候的手动安装。第二个可能只是一些支持副本/可忽略,第三个是自制软件安装。

我怎样才能让 rails 使用自制的 postgres 安装,即使这意味着删除本地数据库?只要 heroku 上的产品是完整的,这很好。

几天来我一直在重新配置我的开发环境,从 sqlite 到 postgres,这是非常有问题的,因为我现在有一个生产数据库和站点,这迫使我在无法验证的情况下进行一些代码推送本地功能,但在很大程度上完全削弱了我进行任何开发的能力。

请帮帮我!

最佳答案

看起来问题是当数据库是由 9.3.x 创建时您正在启动 9.4.1。

Rails 使用的 posgres 版本应该是正在运行的版本。所以如果你想在 9.3.x 版本中启动 postgres,那么你应该启动那个版本。但是您必须为该版本指定正确的路径。

你得到这些结果是什么?

> initdb --version
> pg_ctl --version
> postgres --version
> psql --version

应该都是一样的。如果它显示 9.4.x 并且你想使用该版本,那么你可以像这样重新初始化数据库:initdb -D/usr/local/var/postgres-4.1 然后你可以开始postgres postgres -D/usr/local/var/postgres-4.1。这样做,您可能会丢失本地数据库,因为听起来该数据是由 9.3.x 创建的。

或者,如果那些输出 9.3.x,那么您应该能够使用没有二进制文件完整路径的命令:postgres -D/usr/local/var/postgres

如果您使用的是 9.4.x 并且想继续使用 9.3.x,请尝试 which postgres。它可能指向 /usr/local/bin。然后确保这只是指向自制版本的链接。 ls -la/usr/local/bin | grep "postgres ->".

如果您使用的是自制软件版本,您可以执行 brew switch postgres 9.3.x 告诉自制软件使用该版本。然后你应该可以用 postgres -D/var/local/var/postgres 启动 postgres。

关于ruby-on-rails - 如何指定 rails 使用哪个 postgres 副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28420092/

相关文章:

ruby-on-rails - 加入 Tables & Rails

python - Django 表单查询数据库(模型)

javascript - Ruby on Rails 嵌入按钮

postgresql - 如何列出表的记录以及通过关系使用了多少的计数器

javascript - 干净利落!当用户点击 link_to image_tag 时模型的属性

sql - 如何按rails中关联的created_at列排序?

sql - datetime 的值始终为 nil

postgresql - Docker-compose : Postgresql ECONNREFUSED

PHP pg_prepare() 表名作为参数

ruby-on-rails-4 - sqlite boolean 't' 和 'f' 带有 rails 事件记录