I have a problem with copying filtered data from one table to another (with similar structure). Basically, I have one big table with about 11 billion rows, and I'd like to copy to another table records that are unique based on one of the columns (called "fingerprint"). I tried something like this:
INSERT INTO table2 SELECT DISTINCT ON (fingerprint) * FROM table1;
It generally works, but it's slow; I tested it on a smaller table consisting of 800 000 rows and it took nearly an hour. I tried changing INSERT to a pair of COPY (with binary option) statements but it was even worse somehow...
I run the psql server on Linux LMDE, i5-2410m with 6gigs of RAM. I dunno if it should take so long and whether there's a way to improve that. I'd appreciate any hints.