0002_autovac_for_index_cleanup_v0.patch
text/x-patch
Filename: 0002_autovac_for_index_cleanup_v0.patch
Type: text/x-patch
Part: 1
Patch
Format: context
Series: patch v0
| File | + | − |
|---|---|---|
| src/backend/postmaster/autovacuum.c | 14 | 0 |
| src/backend/utils/adt/pgstatfuncs.c | 36 | 0 |
*** a/src/backend/postmaster/autovacuum.c
--- b/src/backend/postmaster/autovacuum.c
***************
*** 2791,2796 **** table_recheck_autovac(Oid relid, HTAB *table_toast_map,
--- 2791,2803 ----
effective_multixact_freeze_max_age,
&dovacuum, &doanalyze, &wraparound);
+ /* force vacuum if any index on the rel is requesting cleanup scan */
+ if (!dovacuum)
+ dovacuum =
+ DatumGetBool(
+ DirectFunctionCall1(pg_stat_get_vac_cleanup_needed,
+ ObjectIdGetDatum(relid)));
+
/* ignore ANALYZE for toast tables */
if (classForm->relkind == RELKIND_TOASTVALUE)
doanalyze = false;
***************
*** 3045,3050 **** relation_needs_vacanalyze(Oid relid,
--- 3052,3064 ----
/* Determine if this table needs vacuum or analyze. */
*dovacuum = force_vacuum || (vactuples > vacthresh);
*doanalyze = (anltuples > anlthresh);
+
+ /* still force vacuum if index cleanup is requested */
+ if (!*dovacuum)
+ *dovacuum =
+ DatumGetBool(
+ DirectFunctionCall1(pg_stat_get_vac_cleanup_needed,
+ ObjectIdGetDatum(relid)));
}
else
{
*** a/src/backend/utils/adt/pgstatfuncs.c
--- b/src/backend/utils/adt/pgstatfuncs.c
***************
*** 349,361 **** pg_stat_get_vac_cleanup_needed(PG_FUNCTION_ARGS)
ReleaseSysCache(reltup);
}
if (!is_index)
! PG_RETURN_NULL();
! if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
! result = true;
else
! result = tabentry->needs_vacuum_cleanup;
PG_RETURN_BOOL(result);
}
--- 349,393 ----
ReleaseSysCache(reltup);
}
+ /*
+ * If normal relaion is specified, return true if any index of the
+ * relation is explicitly requesting cleanup.
+ */
if (!is_index)
! {
! Relation indrel;
! SysScanDesc indscan;
! HeapTuple indtup;
! result = false;
! indrel = heap_open(IndexRelationId, AccessShareLock);
! indscan = systable_beginscan(indrel, InvalidOid, false, NULL, 0, NULL);
! while (HeapTupleIsValid(indtup = systable_getnext(indscan)) &&
! !result)
! {
! Form_pg_index ind = (Form_pg_index) GETSTRUCT(indtup);
!
! if (ind->indrelid != relid)
! continue;
!
! if ((tabentry = pgstat_fetch_stat_tabentry(ind->indexrelid)))
! result |= tabentry->needs_vacuum_cleanup;
! }
! systable_endscan(indscan);
! heap_close(indrel, AccessShareLock);
! }
else
! {
! /*
! * Elsewise reutrn the status of the index. As somewhat inconsistent
! * behavior with the normal relation case above, *true* is returned
! * for indexes with no stats here.
! */
! if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
! result = true;
! else
! result = tabentry->needs_vacuum_cleanup;
! }
PG_RETURN_BOOL(result);
}