4848 * (iii) add it to the appropriate options struct (perhaps StdRdOptions)
4949 * (iv) add it to the appropriate handling routine (perhaps
5050 * default_reloptions)
51- * (v) don't forget to document the option
51+ * (v) make sure the lock level is set correctly for that operation
52+ * (vi) don't forget to document the option
5253 *
5354 * Note that we don't handle "oids" in relOpts because it is handled by
5455 * interpretOidsOption().
56+ *
57+ * The default choice for any new option should be AccessExclusiveLock.
58+ * In some cases the lock level can be reduced from there, but the lock
59+ * level chosen should always conflict with itself to ensure that multiple
60+ * changes aren't lost when we attempt concurrent changes.
61+ * The choice of lock level depends completely upon how that parameter
62+ * is used within the server, not upon how and when you'd like to change it.
63+ * Safety first. Existing choices are documented here, and elsewhere in
64+ * backend code where the parameters are used.
65+ *
66+ * In general, anything that affects the results obtained from a SELECT must be
67+ * protected by AccessExclusiveLock.
68+ *
69+ * Autovacuum related parameters can be set at ShareUpdateExclusiveLock
70+ * since they are only used by the AV procs and don't change anything
71+ * currently executing.
72+ *
73+ * Fillfactor can be set because it applies only to subsequent changes made to
74+ * data blocks, as documented in heapio.c
75+ *
76+ * n_distinct options can be set at ShareUpdateExclusiveLock because they
77+ * are only used during ANALYZE, which uses a ShareUpdateExclusiveLock,
78+ * so the ANALYZE will not be affected by in-flight changes. Changing those
79+ * values has no affect until the next ANALYZE, so no need for stronger lock.
80+ *
81+ * Planner-related parameters can be set with ShareUpdateExclusiveLock because
82+ * they only affect planning and not the correctness of the execution. Plans
83+ * cannot be changed in mid-flight, so changes here could not easily result in
84+ * new improved plans in any case. So we allow existing queries to continue
85+ * and existing plans to survive, a small price to pay for allowing better
86+ * plans to be introduced concurrently without interfering with users.
87+ *
88+ * Setting parallel_workers is safe, since it acts the same as
89+ * max_parallel_workers_per_gather which is a USERSET parameter that doesn't
90+ * affect existing plans or queries.
5591 */
5692
5793static relopt_bool boolRelOpts [] =
@@ -267,7 +303,7 @@ static relopt_int intRelOpts[] =
267303 "effective_io_concurrency" ,
268304 "Number of simultaneous requests that can be handled efficiently by the disk subsystem." ,
269305 RELOPT_KIND_TABLESPACE ,
270- AccessExclusiveLock
306+ ShareUpdateExclusiveLock
271307 },
272308#ifdef USE_PREFETCH
273309 - 1 , 0 , MAX_IO_CONCURRENCY
@@ -280,7 +316,7 @@ static relopt_int intRelOpts[] =
280316 "parallel_workers" ,
281317 "Number of parallel processes that can be used per executor node for this relation." ,
282318 RELOPT_KIND_HEAP ,
283- AccessExclusiveLock
319+ ShareUpdateExclusiveLock
284320 },
285321 -1 , 0 , 1024
286322 },
@@ -314,7 +350,7 @@ static relopt_real realRelOpts[] =
314350 "seq_page_cost" ,
315351 "Sets the planner's estimate of the cost of a sequentially fetched disk page." ,
316352 RELOPT_KIND_TABLESPACE ,
317- AccessExclusiveLock
353+ ShareUpdateExclusiveLock
318354 },
319355 -1 , 0.0 , DBL_MAX
320356 },
@@ -323,7 +359,7 @@ static relopt_real realRelOpts[] =
323359 "random_page_cost" ,
324360 "Sets the planner's estimate of the cost of a nonsequentially fetched disk page." ,
325361 RELOPT_KIND_TABLESPACE ,
326- AccessExclusiveLock
362+ ShareUpdateExclusiveLock
327363 },
328364 -1 , 0.0 , DBL_MAX
329365 },
@@ -332,7 +368,7 @@ static relopt_real realRelOpts[] =
332368 "n_distinct" ,
333369 "Sets the planner's estimate of the number of distinct values appearing in a column (excluding child relations)." ,
334370 RELOPT_KIND_ATTRIBUTE ,
335- AccessExclusiveLock
371+ ShareUpdateExclusiveLock
336372 },
337373 0 , -1.0 , DBL_MAX
338374 },
@@ -341,7 +377,7 @@ static relopt_real realRelOpts[] =
341377 "n_distinct_inherited" ,
342378 "Sets the planner's estimate of the number of distinct values appearing in a column (including child relations)." ,
343379 RELOPT_KIND_ATTRIBUTE ,
344- AccessExclusiveLock
380+ ShareUpdateExclusiveLock
345381 },
346382 0 , -1.0 , DBL_MAX
347383 },
0 commit comments