Skip to main content
Spree works with all major relational databases supported by Ruby on Rails. You can choose the database that best fits your needs.

Supported Databases

DatabaseDevelopmentProductionNotes
PostgreSQLYesYesRecommended for production. Best performance for large catalogs and high traffic
MySQLYesYesFully supported. A great choice if your team already uses MySQL
SQLiteYesYesZero-configuration setup. Ideal for development, small stores, and getting started quickly

Configuring Your Database

Using DATABASE_URL

The simplest way to configure your database is via the DATABASE_URL environment variable:
# PostgreSQL
DATABASE_URL=postgres://user:pass@localhost:5432/spree

# MySQL
DATABASE_URL=mysql2://user:pass@localhost:3306/spree

# SQLite
DATABASE_URL=sqlite3:db/production.sqlite3

Using database.yml

You can also configure the database in config/database.yml:
default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: spree_development

production:
  <<: *default
  database: spree_production
  url: <%= ENV["DATABASE_URL"] %>

Switching Databases

The easiest way to switch your existing Spree application to a different database is using the built-in Rails command:
# Switch to PostgreSQL
bin/rails db:system:change --to=postgresql

# Switch to MySQL
bin/rails db:system:change --to=mysql

# Switch to SQLite
bin/rails db:system:change --to=sqlite3
This command will:
  • Update your Gemfile with the correct database gem
  • Generate a new config/database.yml configured for the selected database
After running the command, complete the switch:
  1. Install the new gem:
    bundle install
    
  2. Create the new database and run migrations:
    bin/rails db:create db:migrate
    
  3. Optionally load sample data:
    bin/rails spree_sample:load
    

Creating a New App with a Specific Database

When creating a new Spree application with the manual installation method, pass the -d flag to rails new:
# PostgreSQL
rails new my_store -d postgresql -m https://raw.githubusercontent.com/spree/spree/main/backend/template.rb

# MySQL
rails new my_store -d mysql -m https://raw.githubusercontent.com/spree/spree/main/backend/template.rb

# SQLite (default, no flag needed)
rails new my_store -m https://raw.githubusercontent.com/spree/spree/main/backend/template.rb

Cloud Database Services

For production deployments, you can use managed database services:
ProviderPostgreSQLMySQL
AWSRDS PostgreSQL, Aurora PostgreSQLRDS MySQL, Aurora MySQL, RDS MariaDB
Google CloudCloud SQL for PostgreSQLCloud SQL for MySQL
AzureAzure Database for PostgreSQLAzure Database for MySQL
HerokuHeroku PostgresJawsDB, ClearDB
RenderRender PostgreSQL
Set the DATABASE_URL environment variable to the connection string provided by your cloud provider.