-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change auto vacuum settings on big tables
This should allow autovacuum to kick in for big tables where it has never run.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
h/migrations/versions/8b4b4fdef955_auto_vacuum_annotation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Change auto-vacuum settings on big tables.""" | ||
from alembic import op | ||
|
||
revision = "8b4b4fdef955" | ||
down_revision = "0de98307b3c0" | ||
|
||
BIG_TABLES = [ | ||
"annotation", | ||
"annotation_slim", | ||
"annotation_metadata", | ||
"document", | ||
"user", | ||
"group", | ||
] | ||
|
||
|
||
def upgrade(): | ||
for table in BIG_TABLES: | ||
# Set auto vacuum to kick in after 5% of dead tuples (vs total in the table) are detected | ||
op.execute( | ||
f'ALTER TABLE "{table}" SET (autovacuum_vacuum_scale_factor = 0.05);' | ||
) | ||
|
||
|
||
def downgrade(): | ||
# Set it back to the default value | ||
for table in BIG_TABLES: | ||
op.execute( | ||
f'ALTER TABLE "{table}" SET (autovacuum_vacuum_scale_factor = 0.20);' | ||
) |