Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate data from PostgreSQL to MongoDB

I have to migrate 5 million records from PostgreSQL to MongoDb.

I tried using mongify for the same but as it runs on ruby and I am not at all acquainted with ruby i couldn't solve the errors posed by it.

So, I tried writing a code myself in node.js that would first convert PostgreSQL data into JSON and then insert that JSON into mongoDb. But, this failed as it ate a lot of RAM and not more than 13000 records could be migrated.

Then I thought of writing code in Java because of its garbage collector. It works fine in terms of RAM utilization but the speed is very slow (around 10000 records/hour). At this rate it would take me days to migrate my data.

So, Is there a more efficient and faster way of doing this? Would a python program be faster than the Java program? Or is there any other ready-made tool available for doing the same?

My system configuration is : OS - Windows 7 (64 bit), RAM - 4GB, i3 processor

like image 983
sowmyaa guptaa Avatar asked Feb 02 '17 09:02

sowmyaa guptaa


People also ask

How do I migrate Postgres to MongoDB?

Export the data from your PostgreSQL databases by piping the result of an SQL query into a COPY command, outputting the result either as JSON or TSV. Restructure the data to fit your MongoDB schema by using mongoimport (or as an alternative: use bulkWrite operations to load the data).

Is MongoDB better than PostgreSQL?

If you are looking for a distributed database for modern transactional and analytical applications that are working with rapidly changing, multi-structured data, then MongoDB is the way to go. If a SQL database fits your needs, then Postgres is a great choice.

Is MongoDB faster than PostgreSQL?

MongoDB Performance. Various benchmarks have shown that PostgreSQL outperforms MongoDB for data warehousing and data analysis workloads. But in comparing JSON operations between PostgreSQL and MongoDB, there are benchmarks that show an advantage for both databases.


1 Answers

Seems like I am late to the party. However, this might come in handy to somebody, someday!!!!

The following python-based migration framework should come in handy.

https://github.com/datawrangl3r/pg2mongo

Answering to your performance, the migration of each JSON object will be dynamic and there shouldn't be any memory lock issues when you use the above framework.

Hope it helps!!

like image 199
Sathyasarathi Gunasekaran Avatar answered Sep 28 '22 07:09

Sathyasarathi Gunasekaran