mirror of
https://github.com/postgres/postgres.git
synced 2025-07-21 16:02:15 +03:00
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
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user