diff options
author | Michael Paquier <michael@paquier.xyz> | 2018-10-04 09:00:33 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2018-10-04 09:00:33 +0900 |
commit | 803b1301e8c9aac478abeec62824a5d09664ffff (patch) | |
tree | f4ade5601668689308c4acdd34fef6d6984dd54b /src/backend | |
parent | d173652797cf0cf456ac2c38eca898159a7c19fc (diff) | |
download | postgresql-803b1301e8c9aac478abeec62824a5d09664ffff.tar.gz |
Add option SKIP_LOCKED to VACUUM and ANALYZE
When specified, this option allows VACUUM to skip the work on a relation
if there is a conflicting lock on it when trying to open it at the
beginning of its processing.
Similarly to autovacuum, this comes with a couple of limitations while
the relation is processed which can cause the process to still block:
- when opening the relation indexes.
- when acquiring row samples for table inheritance trees, partition trees
or certain types of foreign tables, and that a lock is taken on some
leaves of such trees.
Author: Nathan Bossart
Reviewed-by: Michael Paquier, Andres Freund, Masahiko Sawada
Discussion: https://postgr.es/m/9EF7EBE4-720D-4CF1-9D0E-4403D7E92990@amazon.com
Discussion: https://postgr.es/m/20171201160907.27110.74730@wrigleys.postgresql.org
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: |