diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/commands/vacuum.c | 26 | ||||
-rw-r--r-- | src/backend/parser/gram.y | 12 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 4e3823b0f0..a86963fc86 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -622,6 +622,7 @@ expand_vacuum_rel(VacuumRelation *vrel, int options) HeapTuple tuple; Form_pg_class classForm; bool include_parts; + int rvr_opts; /* * Since autovacuum workers supply OIDs when calling vacuum(), no @@ -634,7 +635,30 @@ 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); + rvr_opts = (options & VACOPT_SKIP_LOCKED) ? RVR_SKIP_LOCKED : 0; + relid = RangeVarGetRelidExtended(vrel->relation, + AccessShareLock, + rvr_opts, + 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 diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index ce60e99cff..6d23bfb0b3 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10538,6 +10538,8 @@ vacuum_option_elem: { if (strcmp($1, "disable_page_skipping") == 0) $$ = VACOPT_DISABLE_PAGE_SKIPPING; + else if (strcmp($1, "skip_locked") == 0) + $$ = VACOPT_SKIP_LOCKED; else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -10571,6 +10573,16 @@ analyze_option_list: analyze_option_elem: VERBOSE { $$ = VACOPT_VERBOSE; } + | IDENT + { + if (strcmp($1, "skip_locked") == 0) + $$ = VACOPT_SKIP_LOCKED; + else + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("unrecognized ANALYZE option \"%s\"", $1), + parser_errposition(@1))); + } ; analyze_keyword: |