mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Add VACUUM/ANALYZE BUFFER_USAGE_LIMIT option
Add new options to the VACUUM and ANALYZE commands called BUFFER_USAGE_LIMIT to allow users more control over how large to make the buffer access strategy that is used to limit the usage of buffers in shared buffers. Larger rings can allow VACUUM to run more quickly but have the drawback of VACUUM possibly evicting more buffers from shared buffers that might be useful for other queries running on the database. Here we also add a new GUC named vacuum_buffer_usage_limit which controls how large to make the access strategy when it's not specified in the VACUUM/ANALYZE command. This defaults to 256KB, which is the same size as the access strategy was prior to this change. This setting also controls how large to make the buffer access strategy for autovacuum. Per idea by Andres Freund. Author: Melanie Plageman Reviewed-by: David Rowley Reviewed-by: Andres Freund Reviewed-by: Justin Pryzby Reviewed-by: Bharath Rupireddy Discussion: https://postgr.es/m/20230111182720.ejifsclfwymw2reb@awork3.anarazel.de
This commit is contained in:
@@ -87,6 +87,12 @@ typedef struct PVShared
|
||||
*/
|
||||
int maintenance_work_mem_worker;
|
||||
|
||||
/*
|
||||
* The number of buffers each worker's Buffer Access Strategy ring should
|
||||
* contain.
|
||||
*/
|
||||
int ring_nbuffers;
|
||||
|
||||
/*
|
||||
* Shared vacuum cost balance. During parallel vacuum,
|
||||
* VacuumSharedCostBalance points to this value and it accumulates the
|
||||
@@ -365,6 +371,9 @@ parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes,
|
||||
maintenance_work_mem / Min(parallel_workers, nindexes_mwm) :
|
||||
maintenance_work_mem;
|
||||
|
||||
/* Use the same buffer size for all workers */
|
||||
shared->ring_nbuffers = GetAccessStrategyBufferCount(bstrategy);
|
||||
|
||||
pg_atomic_init_u32(&(shared->cost_balance), 0);
|
||||
pg_atomic_init_u32(&(shared->active_nworkers), 0);
|
||||
pg_atomic_init_u32(&(shared->idx), 0);
|
||||
@@ -1018,8 +1027,9 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
|
||||
pvs.indname = NULL;
|
||||
pvs.status = PARALLEL_INDVAC_STATUS_INITIAL;
|
||||
|
||||
/* Each parallel VACUUM worker gets its own access strategy */
|
||||
pvs.bstrategy = GetAccessStrategy(BAS_VACUUM);
|
||||
/* Each parallel VACUUM worker gets its own access strategy. */
|
||||
pvs.bstrategy = GetAccessStrategyWithSize(BAS_VACUUM,
|
||||
shared->ring_nbuffers * (BLCKSZ / 1024));
|
||||
|
||||
/* Setup error traceback support for ereport() */
|
||||
errcallback.callback = parallel_vacuum_error_callback;
|
||||
|
||||
Reference in New Issue
Block a user