Read more

Disable PostgreSQL's Write-Ahead Log to speed up tests

Michael Leimstädtner
January 02, 2024Software engineer at makandra GmbH

The linked article suggests an interesting way to speed up tests of Rails + Postgres apps:

PostgreSQL allows the creation of “unlogged” tables, which do not record data in the PostgreSQL Write-Ahead Log Show archive.org snapshot . This can make the tables faster, but significantly increases the risk of data loss if the database crashes. As a result, this should not be used in production environments. If you would like all created tables to be unlogged in the test environment you can add the following to your test.rb file:

# config/environments/test.rb
ActiveSupport.on_load(:active_record_postgresqladapter) do
  self.create_unlogged_tables = true
end
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

To test the integration, commit the code snipped to your repository, then run your tests and re-record their parallel runtime.

Note

The statement only affects newly created tables. You and everyone on the project might need to re-recreate their test databases like so:
bundle exec rails parallel:drop && bundle exec rails parallel:prepare

Posted by Michael Leimstädtner to makandra dev (2024-01-02 11:42)