Project

General

Profile

Actions

Bug #10879

closed

Postgres DB additional Index on reports for reports dashboard widget

Added by Simon Mügge almost 9 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Category:
Database
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

We just updated our Foreman install with ~14000 hosts to 1.8.2.
When testing the install everything was fine, but as soon as users (~200) where starting to use the Frontend again, everything exploded, because of the reports dashboard widgets performance.

A single dashboard pageload took over 80 seconds on average because the DBquery didn't return before that, so 100+ users firing the same long running query against the db blocked the frontends completely and the DB wasn't too happy either.

So please add an additional index for that dashboard, others with "a lot" of hosts will probably run into that same problem, ymmv depending on number of hosts & report retention time.?

That was my prose, this is actual information from my DB colleague:
Data in 'reports': ~26GB

The query the widget performs on every Dashboard pageload:
SELECT "reports".* FROM "reports" WHERE (status <> 0) AND (("reports"."reported_at" >= '2015-06-12')) ORDER BY "reports"."reported_at" DESC NULLS LAST LIMIT 6;

The pgsql 'explain' for that query said:
Limit (cost=3278039.34..3278039.35 rows=6 width=538)
-> Sort (cost=3278039.34..3282344.48 rows=1722055 width=538)
Sort Key: reported_at
-> Seq Scan on reports (cost=0.00..3247171.83 rows=1722055 width=538)
Filter: ((status <> 0) AND (reported_at >= '2015-06-12 00:00:00'::timestamp without time zone))
(5 rows)

So the DB guy created a new index:
create index concurrently on reports (reported_at DESC NULLS LAST);

The pgsql 'explain' after that index now says:
Limit (cost=0.43..19.91 rows=6 width=538)
-> Index Scan using reports_reported_at_idx on reports (cost=0.43..5096157.42 rows=1569360 width=538)
Index Cond: (reported_at >= '2015-06-12 00:00:00'::timestamp without time zone)
Filter: (status <> 0)
(4 rows)

And now we again have Dashboard pagaloads in under a second.

Actions

Also available in: Atom PDF