aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-12-04 15:23:36 -0500
committerRobert Haas <rhaas@postgresql.org>2017-12-04 15:25:55 -0500
commitab6eaee88420db58a948849d5a735997728d73a9 (patch)
tree3d9abedc861185f4eb6d4c7005b9eb84ca74ea40 /src/backend/commands
parentecc27d55f4c37a8485a7d0e1dae0eb5ef2bc886e (diff)
downloadpostgresql-ab6eaee88420db58a948849d5a735997728d73a9.tar.gz
postgresql-ab6eaee88420db58a948849d5a735997728d73a9.zip
When VACUUM or ANALYZE skips a concurrently dropped table, log it.
Hopefully, the additional logging will help avoid confusion that could otherwise result. Nathan Bossart, reviewed by Michael Paquier, Fabrízio Mello, and me
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/analyze.c46
-rw-r--r--src/backend/commands/vacuum.c49
2 files changed, 84 insertions, 11 deletions
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!
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index cbd6e9b1616..4abe6b15e0d 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -1330,6 +1330,7 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
Oid save_userid;
int save_sec_context;
int save_nestlevel;
+ bool rel_lock = true;
Assert(params != NULL);
@@ -1400,16 +1401,52 @@ vacuum_rel(Oid relid, RangeVar *relation, int options, VacuumParams *params)
else
{
onerel = NULL;
- if (relation &&
- IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
- ereport(LOG,
- (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
- errmsg("skipping vacuum of \"%s\" --- lock not available",
- relation->relname)));
+ rel_lock = false;
}
+ /*
+ * If we failed to open or lock the relation, emit a log message before
+ * exiting.
+ */
if (!onerel)
{
+ int elevel = 0;
+
+ /*
+ * Determine the log level.
+ *
+ * If the RangeVar is not defined, we do not have enough information
+ * to provide a meaningful log statement. Chances are that
+ * vacuum_rel's caller has intentionally not provided this information
+ * so that this logging is skipped, anyway.
+ *
+ * Otherwise, for autovacuum logs, we emit a LOG if
+ * log_autovacuum_min_duration is not disabled. For manual VACUUM, we
+ * emit a WARNING to match the log statements in the permission
+ * checks.
+ */
+ if (relation != NULL)
+ {
+ if (!IsAutoVacuumWorkerProcess())
+ elevel = WARNING;
+ else if (params->log_min_duration >= 0)
+ elevel = LOG;
+ }
+
+ if (elevel != 0)
+ {
+ if (!rel_lock)
+ ereport(elevel,
+ (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
+ errmsg("skipping vacuum of \"%s\" --- lock not available",
+ relation->relname)));
+ else
+ ereport(elevel,
+ (errcode(ERRCODE_UNDEFINED_TABLE),
+ errmsg("skipping vacuum of \"%s\" --- relation no longer exists",
+ relation->relname)));
+ }
+
PopActiveSnapshot();
CommitTransactionCommand();
return false;