Nic*_*ick 73 ruby postgresql ubuntu ruby-on-rails heroku
我目前在Ubuntu 12.04中通过RVM安装了Ruby on Rails.默认数据库是在SQLite3中设置的,但是为了推送到Heroku,我想切换到PostgreSQL.我怎么能做到这一点?
Nic*_*ick 165
以下是我遵循的步骤:
安装PostgreSQL和开发包
$ sudo apt-get install postgresql
$ sudo apt-get install libpq-dev
Run Code Online (Sandbox Code Playgroud)
设置与我的Ubuntu登录相同的用户
$ sudo su postgres -c psql
postgres=# CREATE ROLE <username> SUPERUSER LOGIN;
postgres=# \q
Run Code Online (Sandbox Code Playgroud)
修改Gemfile
# Remove gem 'sqlite3'
gem 'pg'
Run Code Online (Sandbox Code Playgroud)
database.yml在app目录中修改
development:
adapter: postgresql
encoding: unicode
database: appname_development
pool: 5
timeout: 5000
username: <username>
password:
test:
adapter: postgresql
encoding: unicode
database: appname_test
pool: 5
timeout: 5000
username: <username>
password:
Run Code Online (Sandbox Code Playgroud)
运行捆绑安装
$ bundle install
Run Code Online (Sandbox Code Playgroud)
创建数据库和迁移
$ rake db:create:all
$ rake db:migrate
Run Code Online (Sandbox Code Playgroud)
以下是我过去常常提供的帮助来源:http:
//mrfrosti.com/2011/11/postgresql-for-ruby-on-rails-on-ubuntu/
http://railscasts.com/episodes/342-migrating-to -postgresql
https://devcenter.heroku.com/articles/local-postgresql
对于Ubuntu 13.10打开此主题的所有用户,请按照以下步骤进行安装postresql:
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common -t saucy
sudo apt-get install postgresql-9.2 libpq-dev
Run Code Online (Sandbox Code Playgroud)
因为没有正式的Postgres存储库Ubuntu 13.10.
然后创建用户Nick解释(您也可以指定密码):
sudo su postgres -c psql
postgres=# CREATE ROLE gotqn SUPERUSER LOGIN;
postgres=# \password gotqn
postgres=# \q
Run Code Online (Sandbox Code Playgroud)
注意:将gotqn以上内容替换为whoami结果:

创建rails应用程序的最简单方法是指定您使用postgresql如下:
rails new Demo -d postgresql
Run Code Online (Sandbox Code Playgroud)
上面的代码会自动添加pg你的gem GemFile并创建适当的database.yml文件:
development:
adapter: postgresql
encoding: unicode
database: Demo_development
pool: 5
username: gotqn
password: mypass
Run Code Online (Sandbox Code Playgroud)
注意:如果已设置,则需要更改用户名并指定正确的密码.
然后运行rake db:create并启动rails服务器.
| 归档时间: |
|
| 查看次数: |
37866 次 |
| 最近记录: |