From c2377daca7352475289a8e3a8e4e88caabddaa79 Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Thu, 15 Jan 2026 18:32:59 +0100 Subject: [PATCH] Create new database clusuters on every test run The cost of running initdb, especially without fsync, is not very big on modern computers and version of PostgreSQL so the optimization of reusing the same database cluster between test runs is just a potential footgun no longer worth the benefits. It might still be worth caching the generated TLS certificates but for now let's not do that to keep the code simple. --- spec/helpers.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/helpers.rb b/spec/helpers.rb index a17d9a556..340e29cc4 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -251,7 +251,6 @@ def initialize(name, port: 23456, postgresql_conf: '') def create_test_db trace "Creating the test DB" - log_and_run @logfile, pg_bin_path('psql'), '-p', @port.to_s, '-e', '-c', 'DROP DATABASE IF EXISTS test', 'postgres' log_and_run @logfile, pg_bin_path('createdb'), '-p', @port.to_s, '-e', 'test' end @@ -276,12 +275,10 @@ def ca_file private def setup_cluster(postgresql_conf) - return if (@pgdata+"ruby-pg-server-cert").exist? - FileUtils.rm_rf(@pgdata, verbose: $DEBUG) trace "Running initdb" - log_and_run @logfile, pg_bin_path('initdb'), '-E', 'UTF8', '--no-locale', '-D', @pgdata.to_s + log_and_run @logfile, pg_bin_path('initdb'), '-E', 'UTF8', '--no-locale', '--no-sync', '-D', @pgdata.to_s trace "Enable SSL" # Enable SSL in server config @@ -291,6 +288,7 @@ def setup_cluster(postgresql_conf) ssl_ca_file = 'ruby-pg-ca-cert' ssl_cert_file = 'ruby-pg-server-cert' ssl_key_file = 'ruby-pg-server-key' +fsync = off #{postgresql_conf} EOT end