@@ -212,6 +212,15 @@ static bool MatchNamedCall(HeapTuple proctup, int nargs, List *argnames,
212
212
* If flags contains RVR_NOWAIT, throw an error if we'd have to wait for a
213
213
* lock.
214
214
*
215
+ * If flags contains RVR_SKIP_LOCKED, return InvalidOid if we'd have to wait
216
+ * for a lock.
217
+ *
218
+ * flags cannot contain both RVR_NOWAIT and RVR_SKIP_LOCKED.
219
+ *
220
+ * Note that if RVR_MISSING_OK and RVR_SKIP_LOCKED are both specified, a
221
+ * return value of InvalidOid could either mean the relation is missing or it
222
+ * could not be locked.
223
+ *
215
224
* Callback allows caller to check permissions or acquire additional locks
216
225
* prior to grabbing the relation lock.
217
226
*/
@@ -226,6 +235,9 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
226
235
bool retry = false;
227
236
bool missing_ok = (flags & RVR_MISSING_OK ) != 0 ;
228
237
238
+ /* verify that flags do no conflict */
239
+ Assert (!((flags & RVR_NOWAIT ) && (flags & RVR_SKIP_LOCKED )));
240
+
229
241
/*
230
242
* We check the catalog name and then ignore it.
231
243
*/
@@ -363,20 +375,24 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
363
375
*/
364
376
if (!OidIsValid (relId ))
365
377
AcceptInvalidationMessages ();
366
- else if (!(flags & RVR_NOWAIT ))
378
+ else if (!(flags & ( RVR_NOWAIT | RVR_SKIP_LOCKED ) ))
367
379
LockRelationOid (relId , lockmode );
368
380
else if (!ConditionalLockRelationOid (relId , lockmode ))
369
381
{
382
+ int elevel = (flags & RVR_SKIP_LOCKED ) ? DEBUG1 : ERROR ;
383
+
370
384
if (relation -> schemaname )
371
- ereport (ERROR ,
385
+ ereport (elevel ,
372
386
(errcode (ERRCODE_LOCK_NOT_AVAILABLE ),
373
387
errmsg ("could not obtain lock on relation \"%s.%s\"" ,
374
388
relation -> schemaname , relation -> relname )));
375
389
else
376
- ereport (ERROR ,
390
+ ereport (elevel ,
377
391
(errcode (ERRCODE_LOCK_NOT_AVAILABLE ),
378
392
errmsg ("could not obtain lock on relation \"%s\"" ,
379
393
relation -> relname )));
394
+
395
+ return InvalidOid ;
380
396
}
381
397
382
398
/*
0 commit comments