Cloud9 + rails + Postgresql usage

故事扮演 提交于 2019-12-02 11:58:22

Cloud9 does not run PG by defalut. Below is the fast & easy way I use to use Postgresql on C9:

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. Paste the following code alltogether in the console:

`

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

Done! However after not using the app for some hours the db goes to sleep & you have to "switch" Postgres on manually by typing in the console: sudo service postgresql start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!