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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)