Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(error-tracking): prepare indexed cleanup buckets (#90275)

Hugues Pouillot6f11b21a924d
diff --git a/products/error_tracking/backend/migrations/0028_add_symbol_set_cleanup_bucket_index.py b/products/error_tracking/backend/migrations/0028_add_symbol_set_cleanup_bucket_index.py
new file mode 100644
index 000000000000..efa3b700d463
--- /dev/null
+++ b/products/error_tracking/backend/migrations/0028_add_symbol_set_cleanup_bucket_index.py
@@ -0,0 +1,35 @@
+# Generated by Django 5.2.17 on 2026-08-27 15:30
+
+from django.db import migrations, models
+
+from posthog.migration_helpers import SafeAddIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("error_tracking", "0027_add_severity_rules"),
+ ]
+
+ operations = [
+ SafeAddIndexConcurrently(
+ model_name="errortrackingsymbolset",
+ index=models.Index(
+ models.Func(
+ models.Func(
+ models.F("id"),
+ function="uuid_send",
+ output_field=models.BinaryField(),
+ ),
+ models.Value(15),
+ function="get_byte",
+ output_field=models.IntegerField(),
+ ),
+ models.F("last_used"),
+ models.F("created_at"),
+ models.F("id"),
+ name="et_symset_bucket_cleanup_idx",
+ ),
+ ),
+ ]
diff --git a/products/error_tracking/backend/migrations/max_migration.txt b/products/error_tracking/backend/migrations/max_migration.txt
index dd0b2c6853df..1d31b4cdfa3e 100644
--- a/products/error_tracking/backend/migrations/max_migration.txt
+++ b/products/error_tracking/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0027_add_severity_rules
+0028_add_symbol_set_cleanup_bucket_index
diff --git a/products/error_tracking/backend/models.py b/products/error_tracking/backend/models.py
index 06ca4f9ac26d..f0754fe80994 100644
--- a/products/error_tracking/backend/models.py
+++ b/products/error_tracking/backend/models.py
@@ -358,6 +358,15 @@ class ErrorTrackingRelease(UUIDTModel):
db_table = "posthog_errortrackingrelease"
+def symbol_set_cleanup_bucket_expression() -> models.Func:
+ return models.Func(
+ models.Func(models.F("id"), function="uuid_send", output_field=models.BinaryField()),
+ models.Value(15),
+ function="get_byte",
+ output_field=models.IntegerField(),
+ )
+
+
class ErrorTrackingSymbolSet(UUIDTModel):
# Derived from the symbol set reference
ref = models.TextField(null=False, blank=False)
@@ -402,6 +411,13 @@ class ErrorTrackingSymbolSet(UUIDTModel):
# (leading column) and `last_used IS NULL AND created_at < cutoff` (NULL group
# then created_at range), so batch cleanup avoids a full PK-ordered scan.
models.Index(fields=["last_used", "created_at"], name="et_symset_used_created_idx"),
+ models.Index(
+ symbol_set_cleanup_bucket_expression(),
+ models.F("last_used"),
+ models.F("created_at"),
+ models.F("id"),
+ name="et_symset_bucket_cleanup_idx",
+ ),
]
constraints = [