ruby-on-rails – Cloud9 postgres

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Cloud9 postgres前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在Cloud9的Rails应用程序中设置一个postgres数据库.

我按照这里的说明:https://docs.c9.io/setting_up_postgresql.html并设置了一个名为cc_database的数据库.@H_404_3@

我的database.yml文件如下所示:@H_404_3@

development:
  adapter: postgresql
  encoding: sql_ASCII
  database: cc_database
  pool: 5
  username: postgres
  password: password

当我运行rake db:setup我得到以下错误:@H_404_3@

PG::ConnectionBad: FATAL:  Peer authentication Failed for user "postgres"

我对这一切很新,所以任何建议都将不胜感激.@H_404_3@

解决方法

执行以下步骤:

>在cloud9上为postgresql创建一个新的用户名和密码:@H_404_3@

$sudo service postgresql start
$sudo sudo -u postgres psql
postgres=# CREATE USER username SUPERUSER PASSWORD 'password';
postgres=# \q

>在cloud9上创建ENV变量:@H_404_3@

$echo "export USERNAME=username" >> ~/.profile
$echo "export PASSWORD=password" >> ~/.profile
$source ~/.profile

我的database.yml for rails 4.2.0 on cloud9:@H_404_3@

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: <%= ENV['USERNAME'] %>
  password: <%= ENV['PASSWORD'] %>
  host:     <%= ENV['IP'] %>

development:
  <<: *default
  database: sample_app_development

test:
  <<: *default
  database: sample_app_test

production:
  <<: *default
  database: sample_app_production

在Gemfile中包含gem pg并安装:@H_404_3@

gem ‘pg’,‘~> 0.18.2’@H_404_3@

$bundle install

>更新cloud1上的database.yml的template1 postgresql:@H_404_3@

postgres=# UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
postgres=# DROP DATABASE template1;
postgres=# CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
postgres=# UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
postgres=# \c template1
postgres=# VACUUM FREEZE;
postgres=# \q

>从命令行运行:@H_404_3@

bundle exec rake db:create

猜你在找的Ruby相关文章