Skip to content

A platform for community discussion. Free, open, simple.

FIX: Load PostgreSQL structures in a single transaction (#42012)

Alan Guo Xiang Tanaf075e5fb800
diff --git a/config/initializers/000-active_record.rb b/config/initializers/000-active_record.rb
index 8cb8bb63a42..28ff1c33d8e 100644
--- a/config/initializers/000-active_record.rb
+++ b/config/initializers/000-active_record.rb
@@ -1,5 +1,10 @@
# frozen_string_literal: true
+# Concurrent transactional structure loads exhaust PostgreSQL's shared lock-tracking memory.
+if !Discourse.is_parallel_test?
+ ActiveRecord::Tasks::DatabaseTasks.structure_load_flags = { postgresql: "--single-transaction" }
+end
+
# No ActiveRecord for these models. Avoids the "unknown OID" warnings.
# We need it in core, because plugins are not loaded in core tests,
# but the tables are likely still present in the test database.