19

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.

John Korsnes
  • 2,277
  • 2
  • 20
  • 31

7 Answers7

33

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'
Johannes Brodwall
  • 7,673
  • 5
  • 34
  • 28
  • I had another reason for this error: I had "require 'sqlite3'" line in one of my rake tasks deployed on heroku. And that line was not rescued with LoadError. – Alexander Kuznetsov Aug 22 '12 at 10:51
11

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.

Jay Godse
  • 15,163
  • 16
  • 84
  • 131
  • 1
    What about the in-memory database? Does that need a writeable filesystem? – nicholaides Apr 29 '12 at 04:14
  • I don't know, but I would expect it to work. Just remember that if your Rails process dies, you lose all of that data. Also remember to put the handle to the in-memory database in a class variable of a globally accessible object. – Jay Godse May 02 '12 at 21:19
5

Because of theirs arhitecture, Heroku allows only postgres, so sqlite gem not installed.

valodzka
  • 5,535
  • 4
  • 39
  • 50
4

For more recent versions of Sqlite, you may use this instead:

group :development, :test do
  gem 'sqlite3'
end

This fixed it for me.

4

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.

gertas
  • 16,869
  • 1
  • 76
  • 58
  • 2
    However, in my case, heroku was smart enough to ignore the sqlite gem reference in my Gemfile for local devlopment, and automatically switched to PostgreSQL on production without me explicitly specifying it anywhere. It even generates its own database.yml production settings. I wonder why John is getting the above error then? – Joost Schuur Sep 28 '10 at 05:24
0

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.

0

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

Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
Gleb P.
  • 3
  • 2