@@ -57,31 +57,35 @@ static relopt_bool boolRelOpts[] =
57
57
{
58
58
"autovacuum_enabled" ,
59
59
"Enables autovacuum in this relation" ,
60
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
60
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
61
+ ShareUpdateExclusiveLock
61
62
},
62
63
true
63
64
},
64
65
{
65
66
{
66
67
"user_catalog_table" ,
67
68
"Declare a table as an additional catalog table, e.g. for the purpose of logical replication" ,
68
- RELOPT_KIND_HEAP
69
+ RELOPT_KIND_HEAP ,
70
+ AccessExclusiveLock
69
71
},
70
72
false
71
73
},
72
74
{
73
75
{
74
76
"fastupdate" ,
75
77
"Enables \"fast update\" feature for this GIN index" ,
76
- RELOPT_KIND_GIN
78
+ RELOPT_KIND_GIN ,
79
+ AccessExclusiveLock
77
80
},
78
81
true
79
82
},
80
83
{
81
84
{
82
85
"security_barrier" ,
83
86
"View acts as a row security barrier" ,
84
- RELOPT_KIND_VIEW
87
+ RELOPT_KIND_VIEW ,
88
+ AccessExclusiveLock
85
89
},
86
90
false
87
91
},
@@ -95,140 +99,158 @@ static relopt_int intRelOpts[] =
95
99
{
96
100
"fillfactor" ,
97
101
"Packs table pages only to this percentage" ,
98
- RELOPT_KIND_HEAP
102
+ RELOPT_KIND_HEAP ,
103
+ AccessExclusiveLock
99
104
},
100
105
HEAP_DEFAULT_FILLFACTOR , HEAP_MIN_FILLFACTOR , 100
101
106
},
102
107
{
103
108
{
104
109
"fillfactor" ,
105
110
"Packs btree index pages only to this percentage" ,
106
- RELOPT_KIND_BTREE
111
+ RELOPT_KIND_BTREE ,
112
+ AccessExclusiveLock
107
113
},
108
114
BTREE_DEFAULT_FILLFACTOR , BTREE_MIN_FILLFACTOR , 100
109
115
},
110
116
{
111
117
{
112
118
"fillfactor" ,
113
119
"Packs hash index pages only to this percentage" ,
114
- RELOPT_KIND_HASH
120
+ RELOPT_KIND_HASH ,
121
+ AccessExclusiveLock
115
122
},
116
123
HASH_DEFAULT_FILLFACTOR , HASH_MIN_FILLFACTOR , 100
117
124
},
118
125
{
119
126
{
120
127
"fillfactor" ,
121
128
"Packs gist index pages only to this percentage" ,
122
- RELOPT_KIND_GIST
129
+ RELOPT_KIND_GIST ,
130
+ AccessExclusiveLock
123
131
},
124
132
GIST_DEFAULT_FILLFACTOR , GIST_MIN_FILLFACTOR , 100
125
133
},
126
134
{
127
135
{
128
136
"fillfactor" ,
129
137
"Packs spgist index pages only to this percentage" ,
130
- RELOPT_KIND_SPGIST
138
+ RELOPT_KIND_SPGIST ,
139
+ AccessExclusiveLock
131
140
},
132
141
SPGIST_DEFAULT_FILLFACTOR , SPGIST_MIN_FILLFACTOR , 100
133
142
},
134
143
{
135
144
{
136
145
"autovacuum_vacuum_threshold" ,
137
146
"Minimum number of tuple updates or deletes prior to vacuum" ,
138
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
147
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
148
+ ShareUpdateExclusiveLock
139
149
},
140
150
-1 , 0 , INT_MAX
141
151
},
142
152
{
143
153
{
144
154
"autovacuum_analyze_threshold" ,
145
155
"Minimum number of tuple inserts, updates or deletes prior to analyze" ,
146
- RELOPT_KIND_HEAP
156
+ RELOPT_KIND_HEAP ,
157
+ ShareUpdateExclusiveLock
147
158
},
148
159
-1 , 0 , INT_MAX
149
160
},
150
161
{
151
162
{
152
163
"autovacuum_vacuum_cost_delay" ,
153
164
"Vacuum cost delay in milliseconds, for autovacuum" ,
154
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
165
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
166
+ ShareUpdateExclusiveLock
155
167
},
156
168
-1 , 0 , 100
157
169
},
158
170
{
159
171
{
160
172
"autovacuum_vacuum_cost_limit" ,
161
173
"Vacuum cost amount available before napping, for autovacuum" ,
162
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
174
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
175
+ ShareUpdateExclusiveLock
163
176
},
164
177
-1 , 1 , 10000
165
178
},
166
179
{
167
180
{
168
181
"autovacuum_freeze_min_age" ,
169
182
"Minimum age at which VACUUM should freeze a table row, for autovacuum" ,
170
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
183
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
184
+ ShareUpdateExclusiveLock
171
185
},
172
186
-1 , 0 , 1000000000
173
187
},
174
188
{
175
189
{
176
190
"autovacuum_multixact_freeze_min_age" ,
177
191
"Minimum multixact age at which VACUUM should freeze a row multixact's, for autovacuum" ,
178
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
192
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
193
+ ShareUpdateExclusiveLock
179
194
},
180
195
-1 , 0 , 1000000000
181
196
},
182
197
{
183
198
{
184
199
"autovacuum_freeze_max_age" ,
185
200
"Age at which to autovacuum a table to prevent transaction ID wraparound" ,
186
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
201
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
202
+ ShareUpdateExclusiveLock
187
203
},
188
204
-1 , 100000000 , 2000000000
189
205
},
190
206
{
191
207
{
192
208
"autovacuum_multixact_freeze_max_age" ,
193
209
"Multixact age at which to autovacuum a table to prevent multixact wraparound" ,
194
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
210
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
211
+ ShareUpdateExclusiveLock
195
212
},
196
213
-1 , 100000000 , 2000000000
197
214
},
198
215
{
199
216
{
200
217
"autovacuum_freeze_table_age" ,
201
218
"Age at which VACUUM should perform a full table sweep to freeze row versions" ,
202
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
219
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
220
+ ShareUpdateExclusiveLock
203
221
}, -1 , 0 , 2000000000
204
222
},
205
223
{
206
224
{
207
225
"autovacuum_multixact_freeze_table_age" ,
208
226
"Age of multixact at which VACUUM should perform a full table sweep to freeze row versions" ,
209
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
227
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
228
+ ShareUpdateExclusiveLock
210
229
}, -1 , 0 , 2000000000
211
230
},
212
231
{
213
232
{
214
233
"log_autovacuum_min_duration" ,
215
234
"Sets the minimum execution time above which autovacuum actions will be logged" ,
216
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
235
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
236
+ ShareUpdateExclusiveLock
217
237
},
218
238
-1 , -1 , INT_MAX
219
239
},
220
240
{
221
241
{
222
242
"pages_per_range" ,
223
243
"Number of pages that each page range covers in a BRIN index" ,
224
- RELOPT_KIND_BRIN
244
+ RELOPT_KIND_BRIN ,
245
+ AccessExclusiveLock
225
246
}, 128 , 1 , 131072
226
247
},
227
248
{
228
249
{
229
250
"gin_pending_list_limit" ,
230
251
"Maximum size of the pending list for this GIN index, in kilobytes." ,
231
- RELOPT_KIND_GIN
252
+ RELOPT_KIND_GIN ,
253
+ AccessExclusiveLock
232
254
},
233
255
-1 , 64 , MAX_KILOBYTES
234
256
},
@@ -243,47 +265,53 @@ static relopt_real realRelOpts[] =
243
265
{
244
266
"autovacuum_vacuum_scale_factor" ,
245
267
"Number of tuple updates or deletes prior to vacuum as a fraction of reltuples" ,
246
- RELOPT_KIND_HEAP | RELOPT_KIND_TOAST
268
+ RELOPT_KIND_HEAP | RELOPT_KIND_TOAST ,
269
+ ShareUpdateExclusiveLock
247
270
},
248
271
-1 , 0.0 , 100.0
249
272
},
250
273
{
251
274
{
252
275
"autovacuum_analyze_scale_factor" ,
253
276
"Number of tuple inserts, updates or deletes prior to analyze as a fraction of reltuples" ,
254
- RELOPT_KIND_HEAP
277
+ RELOPT_KIND_HEAP ,
278
+ ShareUpdateExclusiveLock
255
279
},
256
280
-1 , 0.0 , 100.0
257
281
},
258
282
{
259
283
{
260
284
"seq_page_cost" ,
261
285
"Sets the planner's estimate of the cost of a sequentially fetched disk page." ,
262
- RELOPT_KIND_TABLESPACE
286
+ RELOPT_KIND_TABLESPACE ,
287
+ AccessExclusiveLock
263
288
},
264
289
-1 , 0.0 , DBL_MAX
265
290
},
266
291
{
267
292
{
268
293
"random_page_cost" ,
269
294
"Sets the planner's estimate of the cost of a nonsequentially fetched disk page." ,
270
- RELOPT_KIND_TABLESPACE
295
+ RELOPT_KIND_TABLESPACE ,
296
+ AccessExclusiveLock
271
297
},
272
298
-1 , 0.0 , DBL_MAX
273
299
},
274
300
{
275
301
{
276
302
"n_distinct" ,
277
303
"Sets the planner's estimate of the number of distinct values appearing in a column (excluding child relations)." ,
278
- RELOPT_KIND_ATTRIBUTE
304
+ RELOPT_KIND_ATTRIBUTE ,
305
+ AccessExclusiveLock
279
306
},
280
307
0 , -1.0 , DBL_MAX
281
308
},
282
309
{
283
310
{
284
311
"n_distinct_inherited" ,
285
312
"Sets the planner's estimate of the number of distinct values appearing in a column (including child relations)." ,
286
- RELOPT_KIND_ATTRIBUTE
313
+ RELOPT_KIND_ATTRIBUTE ,
314
+ AccessExclusiveLock
287
315
},
288
316
0 , -1.0 , DBL_MAX
289
317
},
@@ -297,7 +325,8 @@ static relopt_string stringRelOpts[] =
297
325
{
298
326
"buffering" ,
299
327
"Enables buffering build for this GiST index" ,
300
- RELOPT_KIND_GIST
328
+ RELOPT_KIND_GIST ,
329
+ AccessExclusiveLock
301
330
},
302
331
4 ,
303
332
false,
@@ -308,7 +337,8 @@ static relopt_string stringRelOpts[] =
308
337
{
309
338
"check_option" ,
310
339
"View has WITH CHECK OPTION defined (local or cascaded)." ,
311
- RELOPT_KIND_VIEW
340
+ RELOPT_KIND_VIEW ,
341
+ AccessExclusiveLock
312
342
},
313
343
0 ,
314
344
true,
@@ -344,13 +374,29 @@ initialize_reloptions(void)
344
374
345
375
j = 0 ;
346
376
for (i = 0 ; boolRelOpts [i ].gen .name ; i ++ )
377
+ {
378
+ Assert (DoLockModesConflict (boolRelOpts [i ].gen .lockmode ,
379
+ boolRelOpts [i ].gen .lockmode ));
347
380
j ++ ;
381
+ }
348
382
for (i = 0 ; intRelOpts [i ].gen .name ; i ++ )
383
+ {
384
+ Assert (DoLockModesConflict (intRelOpts [i ].gen .lockmode ,
385
+ intRelOpts [i ].gen .lockmode ));
349
386
j ++ ;
387
+ }
350
388
for (i = 0 ; realRelOpts [i ].gen .name ; i ++ )
389
+ {
390
+ Assert (DoLockModesConflict (realRelOpts [i ].gen .lockmode ,
391
+ realRelOpts [i ].gen .lockmode ));
351
392
j ++ ;
393
+ }
352
394
for (i = 0 ; stringRelOpts [i ].gen .name ; i ++ )
395
+ {
396
+ Assert (DoLockModesConflict (stringRelOpts [i ].gen .lockmode ,
397
+ stringRelOpts [i ].gen .lockmode ));
353
398
j ++ ;
399
+ }
354
400
j += num_custom_options ;
355
401
356
402
if (relOpts )
@@ -1411,3 +1457,41 @@ tablespace_reloptions(Datum reloptions, bool validate)
1411
1457
1412
1458
return (bytea * ) tsopts ;
1413
1459
}
1460
+
1461
+ /*
1462
+ * Determine the required LOCKMODE from an option list.
1463
+ *
1464
+ * Called from AlterTableGetLockLevel(), see that function
1465
+ * for a longer explanation of how this works.
1466
+ */
1467
+ LOCKMODE
1468
+ AlterTableGetRelOptionsLockLevel (List * defList )
1469
+ {
1470
+ LOCKMODE lockmode = NoLock ;
1471
+ ListCell * cell ;
1472
+
1473
+ if (defList == NIL )
1474
+ return AccessExclusiveLock ;
1475
+
1476
+ if (need_initialization )
1477
+ initialize_reloptions ();
1478
+
1479
+ foreach (cell , defList )
1480
+ {
1481
+ DefElem * def = (DefElem * ) lfirst (cell );
1482
+ int i ;
1483
+
1484
+ for (i = 0 ; relOpts [i ]; i ++ )
1485
+ {
1486
+ if (pg_strncasecmp (relOpts [i ]-> name ,
1487
+ def -> defname ,
1488
+ relOpts [i ]-> namelen + 1 ) == 0 )
1489
+ {
1490
+ if (lockmode < relOpts [i ]-> lockmode )
1491
+ lockmode = relOpts [i ]-> lockmode ;
1492
+ }
1493
+ }
1494
+ }
1495
+
1496
+ return lockmode ;
1497
+ }
0 commit comments