Hi Tom, Greg,
Thanks for your helpful suggestions - switching the BIGINT to FLOAT
and fixing the postgresql.conf to better match my server configuration
gave me about 30% speedup on the queries.
Because of the fact that my data insert order was almost never the
data retrieval order, I also got a significant (about 3x - 10x)
speedup by CLUSTERing the tables on an index that represented the most
frequent query orders (main_id, timestamp, sub_id, device_id) - the
queries that were taking a few seconds earlier now complete in a few
hundred milliseconds (5s vs. 600ms in some instances).
Thanks Again,
Hrishikesh