Cloud9 + rails + Postgresql用法

我无法使用Postgresql在Cloud9(c9.io)上进行开发来设置Rails应用程序:迁移不成功。

常见错误:

~/workspace (master) $ rake db:migrate rake aborted! PG::ConnectionBad: could not connect to server: Connection refused Is the server running on host "0.0.0.0" and accepting TCP/IP connections on port 5432? 

Cloud9不会通过defalut运行PG。 下面是我在C9上使用Postgresql的快捷方式:

1. Gemfile.rb:

 gem 'pg' 

2. Database.yml:

 default: &default adapter: postgresql encoding: unicode pool: 5 username: my_name password: my_pass host: <%= ENV['IP'] %> development: <<: *default database: my_db_development test: <<: *default database: my_db_test production: <<: *default database: my_db_production 
  1. 将以下代码全部粘贴到控制台中:

`

 sudo service postgresql start sudo sudo -u postgres psql CREATE USER my_name SUPERUSER PASSWORD 'my_pass'; \q echo "export USERNAME=my_name" echo "export PASSWORD=my_pass" source bundle sudo sudo -u postgres psql UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1'; DROP DATABASE template1; CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE'; UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1'; \c template1 VACUUM FREEZE; \q bundle exec rake db:create rake db:migrate 

完成! 然而,在不使用该应用程序几个小时之后,数据库进入睡眠状态并且您必须通过在控制台中键入来手动“切换”Postgres: sudo service postgresql start