@@ -1330,6 +1330,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
1330
1330
Oid save_userid ;
1331
1331
int save_sec_context ;
1332
1332
int save_nestlevel ;
1333
+ bool rel_lock = true;
1333
1334
1334
1335
Assert (params != NULL );
1335
1336
@@ -1400,16 +1401,52 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
1400
1401
else
1401
1402
{
1402
1403
onerel = NULL ;
1403
- if (relation &&
1404
- IsAutoVacuumWorkerProcess () && params -> log_min_duration >= 0 )
1405
- ereport (LOG ,
1406
- (errcode (ERRCODE_LOCK_NOT_AVAILABLE ),
1407
- errmsg ("skipping vacuum of \"%s\" --- lock not available" ,
1408
- relation -> relname )));
1404
+ rel_lock = false;
1409
1405
}
1410
1406
1407
+ /*
1408
+ * If we failed to open or lock the relation, emit a log message before
1409
+ * exiting.
1410
+ */
1411
1411
if (!onerel )
1412
1412
{
1413
+ int elevel = 0 ;
1414
+
1415
+ /*
1416
+ * Determine the log level.
1417
+ *
1418
+ * If the RangeVar is not defined, we do not have enough information
1419
+ * to provide a meaningful log statement. Chances are that
1420
+ * vacuum_rel's caller has intentionally not provided this information
1421
+ * so that this logging is skipped, anyway.
1422
+ *
1423
+ * Otherwise, for autovacuum logs, we emit a LOG if
1424
+ * log_autovacuum_min_duration is not disabled. For manual VACUUM, we
1425
+ * emit a WARNING to match the log statements in the permission
1426
+ * checks.
1427
+ */
1428
+ if (relation != NULL )
1429
+ {
1430
+ if (!IsAutoVacuumWorkerProcess ())
1431
+ elevel = WARNING ;
1432
+ else if (params -> log_min_duration >= 0 )
1433
+ elevel = LOG ;
1434
+ }
1435
+
1436
+ if (elevel != 0 )
1437
+ {
1438
+ if (!rel_lock )
1439
+ ereport (elevel ,
1440
+ (errcode (ERRCODE_LOCK_NOT_AVAILABLE ),
1441
+ errmsg ("skipping vacuum of \"%s\" --- lock not available" ,
1442
+ relation -> relname )));
1443
+ else
1444
+ ereport (elevel ,
1445
+ (errcode (ERRCODE_UNDEFINED_TABLE ),
1446
+ errmsg ("skipping vacuum of \"%s\" --- relation no longer exists" ,
1447
+ relation -> relname )));
1448
+ }
1449
+
1413
1450
PopActiveSnapshot ();
1414
1451
CommitTransactionCommand ();
1415
1452
return false;
0 commit comments