ruby-on-rails – Cloud9 postgres
发布时间:2020-12-16 20:26:51 所属栏目:百科 来源:网络整理
导读:我试图在Cloud9的Rails应用程序中设置一个postgres数据库. 我按照这里的说明:https://docs.c9.io/setting_up_postgresql.html并设置了一个名为cc_database的数据库. 我的database.yml文件如下所示: development: adapter: postgresql encoding: SQL_ASCII
我试图在Cloud9的Rails应用程序中设置一个postgres数据库.
我按照这里的说明:https://docs.c9.io/setting_up_postgresql.html并设置了一个名为cc_database的数据库. 我的database.yml文件如下所示: development: adapter: postgresql encoding: SQL_ASCII database: cc_database pool: 5 username: postgres password: password 当我运行rake db:setup我得到以下错误: PG::ConnectionBad: FATAL: Peer authentication failed for user "postgres" 我对这一切很新,所以任何建议都将不胜感激. 解决方法
执行以下步骤:
>在cloud9上为postgresql创建一个新的用户名和密码: $sudo service postgresql start $sudo sudo -u postgres psql postgres=# CREATE USER username SUPERUSER PASSWORD 'password'; postgres=# q >在cloud9上创建ENV变量: $echo "export USERNAME=username" >> ~/.profile $echo "export PASSWORD=password" >> ~/.profile $source ~/.profile 我的database.yml for rails 4.2.0 on cloud9: 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并安装:
$bundle install >更新cloud1上的database.yml的template1 postgresql: 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 >从命令行运行: bundle exec rake db:create (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |