Ask HN: 120M rows Postgres – how can I speed up queries?
Forgetting the specific queries for a moment (basically all queries in this table are relatively slow):
How would you handle such a scenario? Shard the database?
Forgetting the specific queries for a moment (basically all queries in this table are relatively slow):
How would you handle such a scenario? Shard the database?
https://pgtune.leopard.in.ua/#/
Are you monitoring your machine to check if it is not starving on cpu?
Re the queries, we have been using pgbadger to collect metrics about the usage of the dB and the slowest queries by type. This is helpful as it guides where you should put your efforts.
https://github.com/darold/pgbadger/blob/master/README.md
This is very good ref about scaling Postgres.
https://pyvideo.org/pycon-ca-2017/postgres-at-any-scale.html
We definitely have a decent configuration, in terms of using the hardware best for our typical workload. We also have indexes on the fields we are using for filtering. It’s crazy, I put this question here because I feel like this is an inevitable thing that everybody just runs into over and over with scaling and the only real out is sharding, so I’m glad to see you a bunch of suggestions here and I’m going to watch that video as I mentioned. Thanks again.
In terms of execution plan, the query we are doing is relatively basic even though it includes some aggregation. The aggregation is rule (CASE) based and very simple. It feels like there is no way to quickly (sub-50ms) retrieve information from a database once you reach the high tens of millions of rows.
This technique is a bit advanced, borrowed from hierarchical databases, and optimizes for specific queries known upfront, so it’s cool but not very flexible. There is a lot more to making it work. You can watch [1], if interested.
But I’d also +1 other suggestions here on fine tuning your db engine and just scaling up the server.
[1] https://youtu.be/jzeKPKpucS0
Disclaimer: I’m with AWS.
Sharding by month or other bucket of time could help.
We have a very similar situation except it’s billions of rows. One benefit is it’s a bit denormalized in that we store the meat of our data in a hstore field