by lcnmrn · 7y ago · 0 comments
I used Clickhouse previously with large data like this and worked much better. Obliviously, I compare oranges with apples, but PostgreSQL could support a columnar data engine or some kind of index?
What made that "too slow"?
I just tested it, and it's not too bad. This is on my development environment (~3yo laptop, reasonably powerful), with all kinds of compile-time debugging enabled - but with compiler optimizations turned on.
CREATE TABLE hashes(hash text, count int);
BEGIN;
TRUNCATE hashes;
\copy hashes FROM program '7z e -so ~/tmp/pwned-passwords-sha1-ordered-by-count-v4.7z pwned-passwords-sha1-ordered-by-count-v4.txt' WITH (DELIMITER ':', FREEZE);
Time: 1245024.360 ms (20:45.024)
COMMIT;
The bottleneck is 7z decompressing: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
24403 andres 20 0 31480 22292 4544 R 73.8 0.1 14:54.09 7z
23701 andres 20 0 4380008 11488 9024 S 27.9 0.0 5:42.04 postgres
And with a bit config the PG side could be made consdierably faster.Creating an index:
CREATE INDEX ON hashes(hash COLLATE "C");
Time: 709595.370 ms (11:49.595)
And yes, without the COLLATE, and FREEZE above, it'd have taken a bit longer. But not that much.This is all while I also was working on the same loptop, including recompiling etc.
EDIT: Formatting #2
So what do you mean "too slow?" How long did it take?
I don't have any experience with Clickhouse, and not much with columnar databases in general, but if we're talking about a simple table with one index over one text column, I'm not sure whether it makes any difference if you store the tuples row-wise or column-wise on disk. It's an index that covers 100% of the data either way.
I don't know anything about your server but it sounds like PostgreSQL just wasn't able to get much IO throughput from your storage system. Things like storage hardware, filesystem type, and kernel parameters are the big factors here.
The default settings of postgres are more tuned for OLTP though, while you wanted to do OLAP. At least increasing the per-session memory limit would be advisiable to get anything done in any amount of time (the default is something tiny like 64MB). In general configuring Postgres to use more RAM is important to make things fast.
Hopefully it will be fixed with new parallelism improvements.
It'd be cool if you could report details of the problem you had.
The hardware is important. If you tried to import that data on a $5/mo DO droplet, I wouldn't be surprised by having issues.
Also, gotta wonder if you have good indices on the data.
As others have said, the amount of data you're talking about is not very big. I regularly deal with Postgres databases that are two orders of magnitude larger, and they are lightning fast.