From ab6eaee88420db58a948849d5a735997728d73a9 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Mon, 4 Dec 2017 15:23:36 -0500 Subject: When VACUUM or ANALYZE skips a concurrently dropped table, log it. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hopefully, the additional logging will help avoid confusion that could otherwise result. Nathan Bossart, reviewed by Michael Paquier, Fabrízio Mello, and me --- src/backend/commands/analyze.c | 46 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'src/backend/commands/analyze.c') diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 760d19142ec..f952b3c7328 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -120,6 +120,7 @@ analyze_rel(Oid relid, RangeVar *relation, int options, int elevel; AcquireSampleRowsFunc acquirefunc = NULL; BlockNumber relpages = 0; + bool rel_lock = true; /* Select logging level */ if (options & VACOPT_VERBOSE) @@ -149,15 +150,50 @@ analyze_rel(Oid relid, RangeVar *relation, int options, else { onerel = NULL; - if (relation && - IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0) - ereport(LOG, + rel_lock = false; + } + + /* + * If we failed to open or lock the relation, emit a log message before + * exiting. + */ + if (!onerel) + { + /* + * If the RangeVar is not defined, we do not have enough information + * to provide a meaningful log statement. Chances are that + * analyze_rel's caller has intentionally not provided this + * information so that this logging is skipped, anyway. + */ + if (relation == NULL) + return; + + /* + * Determine the log level. For autovacuum logs, we emit a LOG if + * log_autovacuum_min_duration is not disabled. For manual ANALYZE, + * we emit a WARNING to match the log statements in the permissions + * checks. + */ + if (!IsAutoVacuumWorkerProcess()) + elevel = WARNING; + else if (params->log_min_duration >= 0) + elevel = LOG; + else + return; + + if (!rel_lock) + ereport(elevel, (errcode(ERRCODE_LOCK_NOT_AVAILABLE), errmsg("skipping analyze of \"%s\" --- lock not available", relation->relname))); - } - if (!onerel) + else + ereport(elevel, + (errcode(ERRCODE_UNDEFINED_TABLE), + errmsg("skipping analyze of \"%s\" --- relation no longer exists", + relation->relname))); + return; + } /* * Check permissions --- this should match vacuum's check! -- cgit v1.2.3