Hello,
I recently received some excellent advice for caching the latest data to a separate table, to make pulling the most recent values for every entity in my database much more efficient.
I now have a need to keep a montly “snapshot” of that cache table, which will make looking back at historical values from any period in time much more efficient.
What would be the best way to achieve this?
-
A monthly cron job that does a table COPY and names the new table based on the date? I assume with this approach that when I wanted to query “latest” values at a particular point in time, I’d have to find the appropriate snapshot table. At least querying LATEST ON would have to seach back no more than a month (rather than potentially many months or years to find the latest values).
-
A monthly job that inserts everything from the current/snapshot table into another single table that partitions by month? Would that work, though, if some of the sensor values have timestamps much older than the current month? Presumably the older sensor values would be relegated to older partitions and a query to look for the latest values at that point in time would still have to search back through older partitions? It seems to be this approach would be no different/no better than downsampling the original table that contains all sensor values going back for all time.
Happy to provide more explanation if required.
Thanks.