Postgresql partitioned db is slow as hell on a hot summer day. Seems these queries take forever plus one day:
SELECT MAX(clock) AS clock FROM history WHERE itemid='135968' AND clock <= 1482098389;
No matter how to index, this will seq scan all the indexes, and all the partitioned tables in the past (since clock will not limit the search without the lower bound, and the table is partitioned based on clock).
Limiting the lookback (arbitrarily picked 3days, one day would be as good) makes it great again. See attachment.