From 0b09b586e885de2889288dd49816ea00fe5692ee Mon Sep 17 00:00:00 2001
From: Scott Mead <scott@meads.us>
Date: Tue, 13 May 2025 15:48:16 -0400
Subject: [PATCH v1] Disable parallel query by default.

Change max_parallel_workers_per_gather default from 2 to 0.  When the
planner automatically chooses a parallel plan, the parallel query
infrastructure adds unpredictable overhead to a running postgres system.
This change prevents runaway parallel query execution in cases where
parallel plans are unknowingly chosen.
---
 doc/src/sgml/config.sgml                      | 4 ++--
 src/backend/optimizer/path/costsize.c         | 2 +-
 src/backend/utils/misc/guc_tables.c           | 2 +-
 src/backend/utils/misc/postgresql.conf.sample | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index f923ca13a74..a87f3c083aa 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -2788,8 +2788,8 @@ include_dir 'conf.d'
          <xref linkend="guc-max-parallel-workers"/>.  Note that the requested
          number of workers may not actually be available at run time.  If this
          occurs, the plan will run with fewer workers than expected, which may
-         be inefficient.  The default value is 2.  Setting this value to 0
-         disables parallel query execution.
+         be inefficient.  The default value is 0.  Setting this value to 2 or
+         higher enables parallel query execution.
         </para>
 
         <para>
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index f6f77b8fe19..99d54b45734 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -140,7 +140,7 @@ int			effective_cache_size = DEFAULT_EFFECTIVE_CACHE_SIZE;
 
 Cost		disable_cost = 1.0e10;
 
-int			max_parallel_workers_per_gather = 2;
+int			max_parallel_workers_per_gather = 0;
 
 bool		enable_seqscan = true;
 bool		enable_indexscan = true;
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 17d28f458f2..2b59ece5bf2 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -3619,7 +3619,7 @@ struct config_int ConfigureNamesInt[] =
 			GUC_EXPLAIN
 		},
 		&max_parallel_workers_per_gather,
-		2, 0, MAX_PARALLEL_WORKER_LIMIT,
+		0, 0, MAX_PARALLEL_WORKER_LIMIT,
 		NULL, NULL, NULL
 	},
 
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 0b9e3066bde..25814082425 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -214,7 +214,7 @@
 # - Worker Processes -
 
 #max_worker_processes = 8		# (change requires restart)
-#max_parallel_workers_per_gather = 2	# limited by max_parallel_workers
+#max_parallel_workers_per_gather = 0	# limited by max_parallel_workers
 #max_parallel_maintenance_workers = 2	# limited by max_parallel_workers
 #max_parallel_workers = 8		# number of max_worker_processes that
 					# can be used in parallel operations
-- 
2.39.5 (Apple Git-154)

