v9-0006-Skip-VACUUM-ANALYZE-with-VACOPT_SKIP_LOCKED-if-ex.patch
application/octet-stream
Filename: v9-0006-Skip-VACUUM-ANALYZE-with-VACOPT_SKIP_LOCKED-if-ex.patch
Type: application/octet-stream
Part: 1
Patch
Format: format-patch
Series: patch v9-0006
Subject: Skip VACUUM/ANALYZE with VACOPT_SKIP_LOCKED if expand_vacuum_rel() would block.
| File | + | − |
|---|---|---|
| src/backend/commands/vacuum.c | 23 | 1 |
From 3674e267c86e39664d8281001a903b33eab8c9a9 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <bossartn@amazon.com>
Date: Wed, 5 Sep 2018 14:44:57 +0000
Subject: [PATCH v9 6/7] Skip VACUUM/ANALYZE with VACOPT_SKIP_LOCKED if
expand_vacuum_rel() would block.
---
src/backend/commands/vacuum.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 764559f043..07c509646f 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -528,7 +528,29 @@ expand_vacuum_rel(VacuumRelation *vrel, int options)
* below, as well as find_all_inheritors's expectation that the caller
* holds some lock on the starting relation.
*/
- relid = RangeVarGetRelid(vrel->relation, AccessShareLock, false);
+ relid = RangeVarGetRelidExtended(vrel->relation,
+ AccessShareLock,
+ (options & VACOPT_SKIP_LOCKED) ? RVR_SKIP_LOCKED : 0,
+ NULL, NULL);
+
+ /*
+ * If the lock is unavailable, emit the same log statement that
+ * vacuum_rel() and analyze_rel() would.
+ */
+ if (!OidIsValid(relid))
+ {
+ if (options & VACOPT_VACUUM)
+ ereport(WARNING,
+ (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
+ errmsg("skipping vacuum of \"%s\" --- lock not available",
+ vrel->relation->relname)));
+ else
+ ereport(WARNING,
+ (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
+ errmsg("skipping analyze of \"%s\" --- lock not available",
+ vrel->relation->relname)));
+ return vacrels;
+ }
/*
* To check whether the relation is a partitioned table and its
--
2.16.2