How to Migrate 50M Records from Mongo to PostgreSQL in Less Than a Day
tech.plug.dj
tech.plug.dj
Dump the first DB, import into the second? Maybe a couple ETL scripts in between to massage the data?
This task sounds like monodb_dump export_db (or whatever they call their backup tool) | etl.sh | psql -d import_db. Of course shell scripts probably aren't 'webscale' enough to handle 150 GB of data.
Protip: When IO is saturated, make the IO sequential before ever even thinking about threads. Exactly how are more CPUs supposed to make the disk faster? The best you'll do is exploit the command queue more fully.
It should not be the latter, unless there are a lot of indexes that were not dropped before the bulk load, or the ETL works one...row...at...a...time...
Even a simple 'mongoexport --csv | psql -c "COPY FROM stdin"' should faster for 50M records.
There are only 50 million rows... this sounds like a 5 minute query.
just wondering what the tradeoffs were in OP's eyes.
The key is keeping the pipe full, requesting a piece of data based on what's in the pipe will mean that it's going to be hard to keep the pipe full. You want to request the data long before you're ever going to need it.
If your SQL queries are done in such a way that they don't depend on data in the pipe they'll work fast, if they aren't you'll be not much better off than whatever was currently in place.
This is not hard work. I'm not sure exactly what was being done that made this take more than an hour.
On our kit, which is pretty hefty, I'd schedule a 30 minute window for a 150Gb ETL even with heavy transformations.
When we moved our stuff from Mongo to SQL Server it took an entire 6 minutes to drag 30Gb over including SQL full text. That was a 16 core Xeon with 64Gb of RAM and 15K SAS RAID 10 so not a big machine either.
For these cases, I started using GNU parallel instead of plain shell. It does the heavy concurrency lifting for you, and even allow almost seamless parallelization across different machines.
For example, your final code could be written as such:
parallel ./settings.sh python bin/migrate_media.py {} $LIMIT ::: $(seq 0 $LIMIT $NUMPLAYLISTS)
http://www.gnu.org/software/parallel/In reality, most of what Mongo does can be done just as well if not better in Postgresql 9.3 (and I hear good things about 9.4). Then you can simultaneously have structured data via postgres
Wait. What?! The response to being I/O bound is not using more processes...
For reference, I was handling 30M daily records in about an hour on hardware 15 years ago. This performance is absurd.
Take a look at postgres hstore with a gin index.
Now, with the jsonb support coming in 9.4, PG gets pretty much everything I once liked Mongo for.
http://www.postgresql.org/message-id/E1WRpmB-0002et-MT@gemul...
http://thebuild.com/presentations/pg-as-nosql-pgday-fosdem-2...
Furthermore, consider that PG is pretty much an amazing RDBMS in addition to having a good document story.