Skip to content

Comments

[18.0][ADD] database_autovacuum_tuning#3523

Open
santostelmo wants to merge 1 commit intoOCA:18.0from
camptocamp:18.0-add-database_autovacuum_tuning
Open

[18.0][ADD] database_autovacuum_tuning#3523
santostelmo wants to merge 1 commit intoOCA:18.0from
camptocamp:18.0-add-database_autovacuum_tuning

Conversation

@santostelmo
Copy link
Contributor

Database Autovacuum Tuning helps administrators keep PostgreSQL healthy by
exposing recommended autovacuum settings in Odoo. It provides guidance for sizing thresholds and scale factors so large, busy databases
avoid table bloat and excessive vacuum lag. Use it to standardize autovacuum
configuration across environments and speed up maintenance operations without
manual tuning.

@santostelmo santostelmo marked this pull request as draft February 18, 2026 08:28
@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch from 08b065a to 04cc152 Compare February 18, 2026 10:09
@santostelmo santostelmo marked this pull request as ready for review February 18, 2026 10:39
@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch from 04cc152 to afe120e Compare February 18, 2026 10:41
@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch 2 times, most recently from 27d3824 to 22accc3 Compare February 18, 2026 12:30
@santostelmo santostelmo marked this pull request as draft February 18, 2026 13:34
@santostelmo santostelmo marked this pull request as ready for review February 18, 2026 13:36
@santostelmo santostelmo marked this pull request as draft February 18, 2026 13:37
@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch from c6f5a98 to 22accc3 Compare February 18, 2026 13:51
@santostelmo
Copy link
Contributor Author

santostelmo commented Feb 18, 2026

CI failling on auditlog module but don't see any relation with this PR:
Test: auditlog.tests.test_auditlog
AssertionError: Found unexpected attributes on res.groups: export_data unlink write auditlog_ruled_read auditlog_ruled_create auditlog_ruled_write read auditlog_ruled_unlink auditlog_ruled_export_data create

Copy link

@wouitmil wouitmil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch from 22accc3 to 3e9cffc Compare February 19, 2026 05:56
@santostelmo santostelmo marked this pull request as ready for review February 19, 2026 08:10
@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch from 3e9cffc to d20f0cd Compare February 23, 2026 05:44
.sudo()
.get_param(
"database_autovacuum_tuning.autovacuum_vacuum_max_threshold",
default="100000",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default="100000",
default="0",

"database_autovacuum_tuning.autovacuum_vacuum_max_threshold",
default="100000",
)
or 100000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or 100000
or 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the parameter is unset, we want 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the parameter is unset, we want 0 => Changed that

.sudo()
.get_param(
"database_autovacuum_tuning.autovacuum_vacuum_analyze_max_threshold",
default="50000",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default="50000",
default="0",


@api.model
def _tune(self):
vacuum_threshold = int(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle ValueError (for an empty string, something that does not parse as an integer)

"database_autovacuum_tuning.autovacuum_vacuum_analyze_max_threshold",
default="50000",
)
or 50000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or 50000
or 0

@@ -0,0 +1,21 @@
1. Install the module on the database you want to tune.
2. Ensure the `pgstattuple` extension is installed in PostgreSQL.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Ensure the `pgstattuple` extension is installed in PostgreSQL.

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_database_autovacuum_tuning_system,access_database_autovacuum_tuning_system,model_database_autovacuum_tuning,base.group_system,1,1,1,1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
access_database_autovacuum_tuning_system,access_database_autovacuum_tuning_system,model_database_autovacuum_tuning,base.group_system,1,1,1,1
access_database_autovacuum_tuning_system,access_database_autovacuum_tuning_system,model_database_autovacuum_tuning,base.group_system,1,0,1,1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems fair to me. The system user does not need to write to the registers.

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.cr.execute("CREATE EXTENSION IF NOT EXISTS pgstattuple")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cls.env.cr.execute("CREATE EXTENSION IF NOT EXISTS pgstattuple")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using pgstattuple extension anymore

def _get_dead_tuples(self, schemaname="public", tablename="res_partner"):
table = f"{schemaname}.{tablename}"
self.env.cr.execute(
"SELECT dead_tuple_count FROM pgstattuple(%s::regclass)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pg_stat_all_tables

def setUpClass(cls):
super().setUpClass()
cls.env.cr.execute("CREATE EXTENSION IF NOT EXISTS pgstattuple")
with cls.env.registry.cursor() as cr:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe cursors are disabled in tests to never commit. If you want to test here I would recommend mocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocking the method now

@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch 2 times, most recently from 45e51db to 9c69e00 Compare February 23, 2026 11:36
@santostelmo santostelmo force-pushed the 18.0-add-database_autovacuum_tuning branch from 9c69e00 to 772221f Compare February 23, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants