Scaling Postgres artwork

Scaling Postgres · Creston Jamison

100K Faster Queries With GPUs! | Scaling Postgres 441

In this episode of Scaling Postgres, we discuss the public beta of Oriole DB, 100,000 times faster queries with GPUs, post pg_restore to-do and a lesson in data integrity. To get the show notes as well as get notified of new episodes, visit: https://www.scalingpostgres.com/episodes/441-100k-faster-queries-with-gpus/ Want to learn more about Postgres performance? Join my FREE training called Postgres Performance Demystified here: https://www.scalingpostgres.com/courses/postgres-performance-demystified/

Nov 12026
19 minlength
30transcript lines
Publishertranscript source

Transcript first 15 of 30 lines

0:00So Aural DB is now in public beta.

0:04Now, I'm excited by this, but I'm also a little saddened by this. But we'll go ahead and talk about that. I hope you, your friends, family and co workers continue to do well.

0:16Our first piece of content is oreldb public beta, a Postgres storage engine for update heavy tables. This is from supabase.com so the oreldb team did join supabase and now they are moving oreldb into a public beta. Now they say it is an open source storage engine for Postgres and it's available on your Supabase plan. I'm not sure if you can run it yourself yet, but they do say, quote, it's not ready for production yet.

0:47So they go through and describe what OralDB offers. Primarily, it's moving from storing dead rows dead tuples in the heap into storing them in an undo log.

0:59And this should have an advantage for update heavy workloads because every update doesn't create a new row. Yes, it enters something in the undo log, but as long as you don't do a rollback it would be much faster just to update in place. But it has more changes than just that. So yes they are using an undo log. Instead of dealing with leftover dead tuples in the heap, they are moving to 64 bit transaction IDs. They do have index organized tables. What that means is that normally you have the heap and then the indexes are a separate structure, whereas in OralDB rows are stored inside the primary key index rather than a separate heap. So a primary key lookup just reads one structure immediately, it doesn't read the index and then consults the heap and then the secondary indexes point to the primary key. Also there's no buffer mapping, so in memory pages link directly to their storage pages and as a result they say page reads are lock free. And they're also using copy on write checkpoints and row level wall, which means they can just write the data that's changed and can reduce disk I O on write heavy workloads. Now this particular beta is on Postgres 17.0 11, so it does not support the 18 series yet.

2:18least that's my understanding.

2:19Now I did mention I'm excited about this because these are all very interesting, but I'm a little bit saddened by it. The reason is because for the longest time it would be great to have a separate storage engine in Postgres that handles update heavy workloads or better handles update heavy workloads because I keep talking about articles and scaling Postgres. If someone has a queue system that gets a lot of updates and inevitably it runs into problems. Why? Because of vacuum. Taking a while to vacuum things up. So if we had a storage engine that just did an update in place with an undo log and you could just create a Cubase table using this different storage engine, that would be ideal. So it would just be another storage engine to use as opposed to Postgres default heap with MVCC where the versions are stored in the heap. But whenever I see any project looking to do this, they always add more to it.

3:16So this project has added 64 bit transaction IDs, they have changed things to index organized tables. So there's all these other different performance improvements they've changed. So it's not as simple as just giving us another storage engine where update heavy workloads aren't as onerous.

3:35So if you're moving from Postgres onto one of these new solutions, you have to deal with all of this newness. It's not just testing an update heavy workload on a different storage engine, but because trying to get a new storage into Postgres has had a bunch of fits and starts. Maybe this is the only way it can be done where you need to make changes in substantial performance in order to do all the work to be able to support MVCC using an undo log. But they did talk about performance and they used a TPCC benchmark and on a 32 VCPU instance with 128 gigabytes of RAM, it was able to process 1.8 times more transactions per minute compared to Supabase Postgres, which is basically a hosted Postgres and also 46% more throughput per dollar than the heap. Now, when the data fit into memory, the gap was smaller. So they are demonstrating more performance. But it's not something that blows the barn doors off necessarily. But they say here, quote, you know, the performance benefits of Orel DB depend on your workload and it helps the most with tables that are updated or deleted often.

4:46So updated order status, inventory counts, job queues, which I mentioned, basically the places where they say heap storage builds up the most blue. So again, it would be great just to have a quote unquote simple undo log storage system we could add alongside Postgres as opposed to having to commit to a larger database product. Because with all these changes they say here workloads that depend on non b Tree indexes like PGvector HNSW may not see gains yet since those indexes run through an experimental bridge. So again, with all these changes they're having to build more into the product to be able to keep feature parity with Postgres. But if you want to learn more, you can definitely check out this announcement and even try out the public beta. Next Piece of Content Cybertek PGEE Gets a GPU Execution Path this is from cybertech PostgreSQL and this is a follow on from the very short blog post or announcement I mentioned last week where Cybertek is now offering a way to process queries on GPUs and this was prompted by them asking the question what happens when PostgreSQL gets a GPU execution path and the Planner decides when to use it? So basically the Postgres planner is in control on whether it uses a GPU execution path or a CPU execution path. The Application still speaks PostgreSQL as it always has. All the SQL stays the same. It's just how those queries get executed. Quote the GPU becomes another execution option available to the Planner. Now, I haven't seen any mention of this being open source. I'm sure this is a paid product, but still it's super fascinating if you're the right kind of customer for something like this. So they say basically the Planner costs different paths alongside the CPU alternatives, and when the GPU path has a lower cost and the engine can prove that the operation can produce a correct Postgres tool result, Postgres can choose it. So I'm not sure about that decision matrix how that happens. But another interesting thing is that a single query can use both. So large scans and aggregates can run on the gpu, whereas other parts of the query like index scans can continue on the cpu. Okay, here it says the GPU only gets work it can handle correctly. So basically large parallel data processing. So it accelerates operations like scalar aggregates such as count, sum, average, min, max group by distinct analytics, parallel aggregates, et cetera. They have certain types of defined data types it can work with. And it's interesting, they say they keep the PostgreSQL visibility rules intact. And this is an interesting thing where they say the data stays on the GPU because a lot of this insane speed is getting that data into the GPU memory. So they say here, quote There is a cost to first execution. A cold query has to build a cached representation of the data, so basically it needs to be loaded up. But once it's there they say GPU performance is simply mind blowing. And that data representation does get packed down. For example, he says a 57 gigabyte retail data set occupies roughly 9.5 gigabytes in GPU memory, so about 20% of the size.

8:02And an IoT data set measuring 158 gigabytes shrank down to about 38 gigabytes. So again, maybe about 20, 25% of the size.

8:13Now, last week they did mention an example where GPU execution time went from 159 seconds to 2.8 milliseconds, which is 57,000 times faster. And they said, you know, that's kind of slow because the Nvidia L40s chips they're using are old. On the modern H200 cards, they've seen something that's 100,000 times faster. Single GPU core. And you can have multiple cards and get close to a linear scale factor they've seen with four cards, about 3.7. And they say here, you know, multiple GPUs can work on the same query, but if you're working with the right type of data and Postgres, this could blow the doors off of anything seemingly just using raw hardware power.

8:57Like, for example, Oriel db. Their benchmark result was two times faster, whereas certain query results, once the data is loaded up, they're reporting as being 100,000 times faster, which is insane. But if you want to learn more, definitely check this out. Next piece of content. There was another episode of Postgres FM last week. This one was called Dump Restore. Done.

9:20Now what? So Nick was joined by Kirk Wolak and they discussed, once you've taken a PG dump and you've PG restored it, what are additional steps you should follow? Now all your data is restored, but is it ready for production level workload? And they specifically mentioned three things that are missing that can tank your performance until those three things are in place. Now, the first thing they mentioned was, of course, statistics. So your statistics need to be rebuilt. Now, on more recent versions of Postgres, those statistics can be carried over, so that's advantageous. But normally you're going to want to run analyze to make sure your statistics are up to date after loading your database with data, the second thing that's missing or isn't updated is the visibility map. And the third thing are hint bits. Now what updates those are, of course, vacuum. So basically, once you have restored your database, you definitely want to run vacuum analyze on your database so you can get the maximum performance out of it. And what's interesting, they also looked at documentation for 28 different platforms and they mentioned only eight of those, 28 actually mentioned the need to analyze after loading data and only three mentioned needing to run vacuum. They also discussed it would be great if Postgres could actually include an vacuum analyze run after doing a PG restore so that people don't have to remember to do this. And they even showed some statistics with regard to performance after you load data compared to running a query before vacuum analyze has been run and then after. But definitely they talked about a lot more subjects. If you're interested, you can definitely listen to the episode here or watch the YouTube video down here.

11:02And related to that Postgres AI has a blog post related to the show Dump restore done. Now what? And here they have a lot of the graphs of the things they covered. So for example, this is one query after logical restore on Postgres 18.

More Scaling Postgres episodes →