Created
November 22, 2013 16:19
-
-
Save datenimperator/7602535 to your computer and use it in GitHub Desktop.
Speed up your Rails sqlite database for large dataset. This should be a Rails initializer, goes into config/initializers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ::ActiveRecord::Base.connection_config[:adapter] == 'sqlite3' | |
if c = ::ActiveRecord::Base.connection | |
# see http://www.sqlite.org/pragma.html for details | |
# Page size of the database. The page size must be a power of two between 512 and 65536 inclusive | |
c.execute 'PRAGMA main.page_size=4096;' | |
# Suggested maximum number of database disk pages that SQLite will hold in memory at once per open database file | |
c.execute 'PRAGMA main.cache_size=10000;' | |
# Database connection locking-mode. The locking-mode is either NORMAL or EXCLUSIVE | |
c.execute 'PRAGMA main.locking_mode=EXCLUSIVE;' | |
# Setting of the "synchronous" flag, "NORMAL" means sync less often but still more than none | |
c.execute 'PRAGMA main.synchronous=NORMAL;' | |
# Journal mode for database, WAL=write-ahead log | |
c.execute 'PRAGMA main.journal_mode=WAL;' | |
# Storage location for temporary tables, indices, views, triggers | |
c.execute 'PRAGMA main.temp_store = MEMORY;' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment