You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To determine if an index is still being used on production, use [Grafana](https://dashboards.gitlab.net/explore?schemaVersion=1&panes=%7B%22pum%22%3A%7B%22datasource%22%3A%22mimir-gitlab-gprd%22%2C%22queries%22%3A%5B%7B%22refId%22%3A%22A%22%2C%22expr%22%3A%22sum+by+%28type%29%28rate%28pg_stat_user_indexes_idx_scan%7Benv%3D%5C%22gprd%5C%22%2C+indexrelname%3D%5C%22INSERT+INDEX+NAME+HERE%5C%22%7D%5B30d%5D%29%29%22%2C%22range%22%3Atrue%2C%22instant%22%3Atrue%2C%22datasource%22%3A%7B%22type%22%3A%22prometheus%22%2C%22uid%22%3A%22mimir-gitlab-gprd%22%7D%2C%22editorMode%22%3A%22code%22%2C%22legendFormat%22%3A%22__auto%22%7D%5D%2C%22range%22%3A%7B%22from%22%3A%22now-1h%22%2C%22to%22%3A%22now%22%7D%7D%7D&orgId=1):
278
+
For GitLab.com, you can check the latest generated [production reports](https://console.postgres.ai/gitlab/reports/)
279
+
on postgres.ai and inspect the `H002 Unused Indexes` file.
269
280
270
-
```sql
271
-
sum by (type)(rate(pg_stat_user_indexes_idx_scan{env="gprd", indexrelname="INSERT INDEX NAME HERE"}[30d]))
272
-
```
281
+
{{< alert type="warning" >}}
273
282
274
-
Because the query output relies on the actual usage of your database, it
275
-
may be affected by factors such as:
283
+
These reports only show indexes that have no recorded usage **since the last statistics reset.**
284
+
They do not guarantee that the indexes are never used.
276
285
277
-
- Certain queries never being executed, thus not being able to use certain
278
-
indexes.
279
-
- Certain tables having little data, resulting in PostgreSQL using sequence
280
-
scans instead of index scans.
286
+
{{< /alert >}}
281
287
282
-
This data is only reliable for a frequently used database with
283
-
plenty of data, and using as many GitLab features as possible.
288
+
### Verifying that an index is unused
289
+
290
+
This section contains resources to help you evaluate an index and confirm that it's safe to remove. Note that
291
+
this is only a suggested guide and is not exhaustive. Ultimately, the goal is to gather enough data to justify
292
+
dropping the index.
293
+
294
+
Be aware that certain factors can give the false impression that an index is unused, such as:
295
+
296
+
- There may be queries that run on self-managed but not on GitLab.com.
297
+
- The index may be used for very infrequent processes such as periodic cron jobs.
298
+
- On tables that have little data, PostgreSQL may initially prefer a sequential scan over an index scan
299
+
until the table is large enough.
300
+
301
+
#### Investigating index usage
302
+
303
+
1. Start by gathering all the metadata available for the index, verifying its name and definition.
304
+
- The index name in the development environment may not match production. It's important to correlate the indexes
305
+
based on definition rather than name. To check its definition, you can:
0 commit comments