Amazon Redshift extension for ActiveRecord 5 (Rails 5) PostgreSQL adapter based off of the existing activerecord5-redshift-adapter.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Amazon Redshift extension for ActiveRecord 5 (Rails 5) PostgreSQL adapter based off of the existing activerecord5-redshift-adapter. This version has 3 primary goals:

  1. Function as an extension of the PostgreSQL ActiveRecord adapter. Overriding or extending as needed to properly account for the differences between PostgreSQL and Redshift.
  2. Create a functioning test suite.
  3. Support the following versions of ActiveRecord:
    • 5.0
    • 5.1
    • 5.2


Add this line to your application's Gemfile:

gem 'postshift'

And then execute:

$ bundle

Or install it yourself as:

$ gem install postshift

In your Rails 5+ database.yml

  adapter: redshift
  port: 5439
  database: your_db
  username: your_user
  password: your_password
  encoding: utf8
  pool: 3
  timeout: 5000


Postshift exposes Redshift table and column options within ActiveRecord migrations.

DISTKEY & SORTKEY Table Configuration

The DISTKEY and SORTKEY can be passed through the create_table syntax:

create_table 'example_table', distkey: 'name', sortkey: 'number' do |t|
	t.string :name
	t.integer :number

Column Compression Encoding

Redshift column compression encoding can be specified inline as an option within migrations:

create_table 'encoding_examples' do |t|
	t.integer :number, encoding: 'delta'

For more information on compression types:

Schema Dump

Several Rake tasks exist to help with performing a schema dump of an existing Redshift database. These utilize the admin scripts provided by Amazon. All actions are performed using ActiveRecord::Base.connection by default.

These views must exist within the Redshift database under the admin schema prior to any dump or restore actions. To generate, simple run:

rake postshift:schema:prepare

Once these views are in place, the dump and restore will be available and functional.

rake postshift:schema:dump
rake postshift:schema:restore


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


To run the full test suite, a functioning Redshift database instance is required. Once provisioned, copy the example configuration and update with your connection information & run the spec migrations:

cp spec/config.example.yml spec/config.yml

rake spec:db:migrate

And finally, you can now run the entire test suite:

rake spec

The spec structure is based on reliance of an available running Redshift instance. These specs can be run separately:

rake spec:isolated	# Run isolated non-Redshift reliant code examples
rake spec:redshift	# Run Redshift reliant code examples

Additionally, there is multi-version test support through Appraisal.

appraisal install
appraisal ar-5.0 rake spec
appraisal ar-5.1 rake spec
appraisal ar-5.2 rake spec


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.