Skip to content

Commit 3725226

Browse files
committed
fix(scheduler): decrease tasks table autovacuum factor settings
The performance of the expireTasks query decreases over time until vacuuming occurs and speed of the query is back to its baseline. The tasks table update rate is very high (ex: frequent state and dates updates) and create table bloat. This commit is an attempts at optimizing the autovacuum settings for the tasks table to trigger cleaning operations more frequently by reducing scale factors. (The pg default autovaccum settings are too high for the tasks table) By vacuuming at 1% modified rows rather than the default 10%, we'll maintain more consistent query performance while preventing excessive dead tuple accumulation I choose the new value somehow arbitrarely. I will keep monitoring the scheduler queries
1 parent c6b2494 commit 3725226

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Knex } from 'knex';
2+
import { TASKS_TABLE } from '../../models/tasks.js';
3+
4+
export async function up(knex: Knex): Promise<void> {
5+
await knex.raw(`
6+
ALTER TABLE ${TASKS_TABLE} SET (
7+
autovacuum_vacuum_scale_factor = 0.01, -- reducing from 10% to 1%
8+
autovacuum_analyze_scale_factor = 0.01, -- reducing from 5% to 1%
9+
autovacuum_vacuum_insert_scale_factor = 0.05 -- reducing from 20% to 5%
10+
);
11+
`);
12+
}
13+
14+
export async function down(): Promise<void> {}

0 commit comments

Comments
 (0)