问题描述
我正在尝试在Cloud9的Rails应用程序中建立一个postgres数据库。
I am trying to set up a postgres database in a Rails app in Cloud9.
我已按照此处的说明进行操作:并建立一个名为cc_database的数据库。
I have followed the instructions here: https://docs.c9.io/setting_up_postgresql.html and set up a database called cc_database.
我的database.yml文件如下所示:
My database.yml file looks like this:
development:
adapter: postgresql
encoding: SQL_ASCII
database: cc_database
pool: 5
username: postgres
password: password
当我运行rake db:setup时,出现以下错误:
When I run rake db:setup I get the following error:
PG::ConnectionBad: FATAL: Peer authentication failed for user "postgres"
我对此很陌生,所以任何建议都将不胜感激。
I am quite new to all this, so any advice would be much appreciated.
推荐答案
执行以下步骤:
-
为cloud9上的postgresql创建新的用户名和密码。 :
Create a new username and password for postgresql on cloud9:
$ sudo service postgresql start
$ sudo sudo -u postgres psql
postgres=# CREATE USER username SUPERUSER PASSWORD 'password';
postgres=# \q
在cloud9上创建ENV变量:
Create ENV variables on cloud9:
$ echo "export USERNAME=username" >> ~/.profile
$ echo "export PASSWORD=password" >> ~/.profile
$ source ~/.profile
我的rails 4.2我的database.yml cloud9上的.0:
My 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中包含宝石 pg
并安装:
$ bundle install
更新 template1 postgresql cloud9上的database.yml:
Update template1 postgresql for database.yml on cloud9:
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
从命令行运行:
From command line run:
bundle exec rake db:create
这篇关于Cloud9 Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!