Skip to content

Instantly share code, notes, and snippets.

Last active March 1, 2023 15:55
What would you like to do?
speed up testsuit by using unlogged tables in PG
# config/environments/test.rb
ActiveSupport.on_load(:active_record_postgresqladapter) do
# For this optimization to work, you need to recreate your test database
self.create_unlogged_tables = true
# Run `RAILS_ENV=test rails c`
puts ActiveRecord::Base.connection.execute("SELECT relpersistence FROM pg_class WHERE relname = 'users'").first
# In case table is unlogged following will be returned:
# {"relpersistence"=>"u"}
# In case table is regular, following will be returned:
Copy link

skatkov commented Feb 23, 2023

More details about this peace of a code could be found hon my twitter:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment