Pushing Rails with SQLite3 to Heroku fails [duplicate]
I experience the same scenario as described in Heroku deployment issue when I try to deploy my Rails 3 app to Heroku and sqlite3 is defined in the gems file.
/usr/ruby1.8.7/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in `require': no such file to load -- sqlite3 (LoadError)
Any clue why this is? The solution defined in the ruby-forum works, I just wondered why.
Make sure you don't include sqlite in your Gemfile in production environments:
This is right:
source :gemcutter
gem 'rails'
group :development, :test do
gem 'sqlite3-ruby', :require => 'sqlite3'
end
This is wrong:
source :gemcutter
gem 'rails'
gem 'sqlite3-ruby', :require => 'sqlite3'
SQLite requires a permanent writable file system. (i.e. Your program ultimately needs access to the POSIX fopen() and fwrite() API calls to a particular file). Heroku does not provide a permanent writable file system. Therefore, SQLite 3 won't work.
Because of theirs arhitecture, Heroku allows only postgres, so sqlite gem not installed.
I thing sqlite3 is intentionally not provided at Heroku because this database system is embedded database which runs in same process as application. Heroku is distributed environment which means same application may run on many machines within many processes. That would give multiple separated sqlite3 instances - totally unrelated (imagine two isolated separate mysqls on two machines).
In distributed environment at least the 'client-server' centralized type database must be used, e.g: MySQL, PostgreSQL, Oracle.
For more recent versions of Sqlite, you may use this instead:
group :development, :test do
gem 'sqlite3'
end
This fixed it for me.
don't forget to remove the following section
Ignore the default SQLite database.
/db/*.sqlite3
from .gitignore
file. It's created with this declaration if you use a "rails new your-application-name" command
Heroku does not support SQLite. From the Heroku article SQLite on Heroku:
While easy to use, SQLite is not intended as a production grade database. Instead Heroku provides production grade PostgreSQL databases as a service.
Why is SQLite a bad fit for running on Heroku?
Disk backed storage
SQLite runs in memory, and backs up its data store in files on disk. While this strategy works well for development, Heroku’s Cedar stack has an ephemeral filesystem. You can write to it, and you can read from it, but the contents will be cleared periodically. If you were to use SQLite on Heroku, you would lose your entire database at least once every 24 hours.
Even if Heroku’s disks were persistent running SQLite would still not be a good fit. Since SQLite does not run as a service, each dyno would run a separate running copy. Each of these copies need their own disk backed store. This would mean that each dyno powering your app would have a different set of data since the disks are not synchronized.
Instead of using SQLite on Heroku you can configure your app to run on Postgres.
精彩评论