How to migrate da data from Mo Mong ngoDB B to Postgres with h - - PowerPoint PPT Presentation
How to migrate da data from Mo Mong ngoDB B to Postgres with h - - PowerPoint PPT Presentation
How to migrate da data from Mo Mong ngoDB B to Postgres with h ToroDB Wh Who we are Ex Exper perts At Your ur Ser ervice > Over 50 specialists in IT infrastructure > Certified, experienced, passionate Based In Switzerland Ba >
Wh Who we are
30/06/2017 Page 2 How to migrate data from MongoDB to Postgres with ToroDB
Ex Exper perts At Your ur Ser ervice
> Over 50 specialists in IT infrastructure > Certified, experienced, passionate
Ba Based In Switzerland
> 100% self-financed Swiss company > Over CHF8 mio. Turnover
Le Lead adin ing I In I Infr fras astructure S Servic vices
> More than 150 customers in CH, D & F > Over 50 SLAs dbi FlexService contracted
dbi services is hiring (career@dbi-services.com)
Ab About me me
30/06/2017 Page 3 How to migrate data from MongoDB to Postgres with ToroDB
Me Mehdi Bada
Consultant +41 79 928 75 48 mehdi.bada[at]dbi-services.com
Ag Agenda
1.Introduction 2.MongoDB 3.ToroDB 4.Migration: from MongoDB to PostgreSQL 5.Conclusion
30/06/2017 Page 4 How to migrate data from MongoDB to Postgres with ToroDB
30/06/2017 Page 5 How to migrate data from MongoDB to Postgres with ToroDB
1 2 3 4 5
In Introd
- duction
ion
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 6
In Intr trod
- ducti
tion
- n
30/06/2017 Page 7 How to migrate data from MongoDB to Postgres with ToroDB
1 2 3 4 5
Mo MongoDB DB
> Overview > Data Model > High availability > Horizontal scalability > Limitations
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 8
Mo MongoDB
Overview
Open Source Horizontal scalability Schema-less Document
- riented
High availability Indexes Rich queries Full CRUD support
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 9
Mo MongoDB
Overview Co Concept mapping
RDBMS MongoDB
Tables Collections Rows/records Documents Queries return rows Queries return cursor Join Embedded document Partition Shard
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 10
Mo MongoDB
Data Model
Da Data ar a are s stored as as d docu cuments Mon MongoD
- DB s
stor
- res B
BSO SON d doc
- cuments (
(Binary J JSO SON) An Analogous s to a database se row Ke Keys and Values
> Key : String > Values types:
> String, number, Boolean, null, array, object
Sp Speci cial k key: _i _id
> Unique identifier > Object id:
{ “_id” : ObjectId(“56e92b9cfdf7bc92bbb3b51f”), “first_name” : “Mike”, “surname” : “Brody”, “city” : ”New-York”, “year” : 1987, }
Date MAC @ PID Counter 12 byte Hex String
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 11
Mo MongoDB
Data Model Re Relational Mo MongoDB sc schema { “f “first_name” : : “Duran and”, ”, “s “surname” : : “Mik ike", “c “city” : : “Geneva" a", “c “country” : : “Swit itzerlan land”, “c “cars”:[ :[ { { “m “model”: : “Ferrar ari”, ”, “y “year”: : 2013 } }
Pers_Id Surname First_name City Mike Durand Geneva 1 Pat Millner London 2 Ortega Alvaro New-York Car_Id Model Year Pers_Id Ferrari 2013 1 Peugeot 2005 2 BMW 2016 1
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 12
Mo MongoDB
High availability Wh Which mechanism ensure high availability ty of your data?
> MongoDB Replication
HA HA is achi hieved ed thr hroug ugh h aut utoma matic failover er Mo MongoDB replicati tion allows: s:
> High availability (HA) > Disaster Recovery (DR)
> Data duplication across multiple database servers / storages
> Functional Segregation
> Topology of replica sets can be used for > Backups, Analytics, Reporting, DR, Read operations…
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 13
Mo MongoDB
High availability Re Replication architecture
Application mongod Secondary mongod Secondary mongod Primary
driver
Replication
Reads Writes
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 14
Mo MongoDB
High availability Au Autom
- mati
tic failover proc
- cess
mongod Primary mongod Secondary mongod Secondary Election of a new primary Heartbeat mongod Secondary mongod Primary Heartbeat Replication New primary is elected
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 15
Mo MongoDB
Horizontal scalability Ve Vertical scalability Inc Increa easing ng CPU, RAM, I/ I/O Sc Scaling g with Mon
- ngoD
- DB
> MongoDB Sharding
mongod ConfigSvr
Shard 0 …
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 16
Mo MongoDB
Horizontal scalability Sh Sharding g Architecture
Application mongod Primary mongod Secondary
mongos (query router)
Shard 1 … mongod Primary mongod Secondary
mongod ConfigSvr mongod ConfigSvr
Sharding
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 17
Mo MongoDB
Limitations No No ACID D transaction
> Atomic transactions only work within the same document
[ . . . { user: 567, products: [ { id: 47, units: 7, }, . . . ] [ ... { user: 567,
- rders:
[ . . . {
- rderId: 24658,
products: [ . . . ] } . . . ] } . . . ]
CART ORDERS This operation is not Atomic!!
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 18
Mo MongoDB
Limitations Mo MongoDB High availability ty is s not t sa safe!!
> Data loss depending the consistency level you choose
Mo MongoDB consi sistency levels
> Unacknowledged: Unsafe - 42% of data loss > Acknowledged: Unsafe > Journaled: Unsafe > Fsynced: Unsafe > Replica Acknowledged: Unsafe > Only majority is safe
ht https://ap aphyr.com/posts/322 322-je jepsen-mo mong ngodb db-st stale-re reads
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 19
Mo MongoDB
Limitations BI BI query y performances issues Mo MongoDB aggregati tion framework rk is s very sl slow
> Need to scan multiple documents > Lots of I/O required to answer the query
Ag Aggr gregati tion
- n on
- n a relati
tion
- nal design
gn is “100x faster” Sol Solution
- n for
- r Mon
- ngoD
- DB BI queries?
> Implement a relational schema!!
30/06/2017 Page 20 How to migrate data from MongoDB to Postgres with ToroDB
1 2 3 4 5
To ToroDB
> What is ToroDB? > How it works? > Why ToroDB?
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 21
To ToroDB
What is ToroDB?
Th The fir first datab abas ase that merges the scalab alabilit ility of f a a NoSQL wi with t the r reliability o y of SQ SQL
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 22
To ToroDB
What is ToroDB? Op Open source ce, docu cument-or
- riented,
, JSO JSON database that runs on
- n top
- p of
- f Pos
- stgr
greSQ SQL BI BI connector for MongoDB JS JSON doc
- cuments
ts are st stored relationally
> Significant storage > I/O savings
Mo MongoDB data is s persi sisti ting in tables s and rows s wi with thin a SQL database
Protocols Abstract Doc Data2Relational Backends
MongoDB, Couchbase, Cassandra... Transforming Docs into Tables and Rows PostgreSQL, DB2, Oracle, Greenplum...
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 23
To ToroDB
How it works? To ToroDB transforms documents to relational tables
> Data is stored in tables > ToroDB analyzes every incoming document and separates metadata (schema) form data (tuples) > 1+ tables per MongoDB collections > ToroDB creates a RDBMS catalog schema per MongoDB database > Dynamic and implicit schema generation
Fu Full c compatibility w with Mo MongoDB
> API programs, clients > CRUD operations including UPDATE
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 24
To ToroDB
How it works? To ToroDB can work as as a s a secondar ary n node o
- n a M
a MongoDB r replic lica s a set
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 25
To ToroDB
Why ToroDB? Native SQL BI Connector Apps: Write data with Mongo API, query with SQL! Data Integration Platform: SQL and NoSQL apps in the same RDBMS
30/06/2017 Page 26 How to migrate data from MongoDB to Postgres with ToroDB
1 2 3 4 5
Mi Migration: n: from Mo Mong ngoDB B to PostgreSQL
> Overview > Prerequisites > Configuration > Demo
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 27
Mi Migration: from Mo MongoDB to PostgreSQL
Overview
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 28
Mi Migration: from Mo MongoDB to Po PostgreSQL
Overview To ToroDB Stampeded uses MongoDB re replica set oplog to to keep track of the modifications in Mo MongoDB
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 29
Mi Migration: from Mo MongoDB to PostgreSQL
Overview Du During the replication To ToroDB Stampeded transforms JSON documents into a relational sc schema
Column Type Encoding
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 30
Mi Migration: from Mo MongoDB to PostgreSQL
Prerequisites Ru Runti time dependencies
Technology Description
MongoDB Install and start MongoDB instances with the replication features (dbi services best practices installation) Replica sets configuration ToroDB Stampede receives data from a MongoDB replica set. A single-node replica set is sufficient. PostgreSQL Install and start a PostgreSQL instance. Create a dedicated user and database. (dbi services best practices) Java ToroDB Stampede is written in Java so a Java Runtime Environment (JRE) required to run it. Java 8 is recommended.
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 31
Mi Migration: from Mo MongoDB to PostgreSQL
Configuration Ar Architectu ture
Mongo Env Postgres Env ToroDB Stampeded schema generation PostgreSQL instance with DMK installed MongoDB instances with DMK installed 192.168.56.102 192.168.56.140
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 32
Mi Migration: from Mo MongoDB to PostgreSQL
Configuration Af After installati tion
- n,
, expor
- rt
t $TOROHOME va variable Cr Create and adapt the ToroDB B configuration file (YAML)
mehdi@MacBook-Pro:/u00/app/torodb/ export TOROHOME /u00/app/torodb/torodb-stampede-1.0.0- beta2” mehdi@MacBook-Pro:/u00/app/torodb/ echo $TOROHOME /u00/app/torodb/torodb-stampede-1.0.0-beta2 mehdi@MacBook-Pro:/u00/app/torodb/ /u00/app/torodb/torodb-stampede-1.0.0-beta2/bin/torodb- stampede -l > ../conf/torodb.yaml mehdi@MacBook-Pro:/u00/app/torodb/ vi ../conf/torodb.yaml
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 33
Mi Migration: from Mo MongoDB to PostgreSQL
Configuration To ToroDB Stampeded reads databases credentials from the .t .toropass file file Cr Create the .toropass file in the home directory
mehdi@MacBook-Pro:/u00/app/torodb/ echo ”<host>:<port>:<database>:<user>:<PASSWD>" > "$HOME/.toropass" mehdi@MacBook-Pro:/u00/app/torodb/ chmod 0400 ”~/.toropass”
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 34
Mi Migration: from Mo MongoDB to PostgreSQL
Configuration Cu Custom configuration for ToroDB B Stampeded on startup
> Command line options > Configuration file
Re Recommended to use a configuration file Pr Print the current co configuration (YAML)
mehdi@MacBook-Pro:/u00/app/torodb/ ./torodb-stampede -c myconfiguration.yml mehdi@MacBook-Pro:/u00/app/torodb/ ./torodb-stampede -l
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 35
Mi Migration: from Mo MongoDB to PostgreSQL
Demo
Steps Description
1 Ja Java 8 (J (JRE) ) In Installa allatio ion an and Config figuratio ion: http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jre-8u131- linux-x64.tar.gz 2 Po PostgreSQL In Installa allatio ion an and Config figuratio ion:
- Modify, if needed, PostgreSQL instance configuration: /u02/pgdata/PG1/postgresql.conf
https://www.torodb.com/stampede/docs/1.0.0-beta2/configuration/postgresql-configuration-tips/
- Create user torodb and database torod (with password)
- Test the connection with new user and databases
- Adapt pg_hba.conf for new connections
3 Mo MongoDB Installati tion and Configurati tion:
- Configure and initialize MongoDB replication: replset = torodb
- Check replication config. (primary and secondary)
- Import data into MongoDB
4 ToroDB Stampede Installation and Configuration:
- torodb.yaml configuration file creation
- .toropass file creation for creation
- Start ToroDB Stampeded
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 36
Mi Migration: from Mo MongoDB to PostgreSQL
Demo
30/06/2017 Page 37 How to migrate data from MongoDB to Postgres with ToroDB
1 2 3 4 5
Co Conclusion
> Advantages vs Drawbacks
30/06/2017 How to migrate data from MongoDB to Postgres with ToroDB Page 38
Co Conclusion
Advantages vs Drawbacks
Fast and Powerful Dynamic schema generation Only supports PostgreSQL as RDBMS backend Dynamic changes in the schema Open source and free!! Cross-platform: Linux, Windows Need improvements for different schema in the same mongo collection
Any y questions?
Please do ask!
We would love to boost your IT-Infrastructure Ho How a about yo you?
Zürich Basel Delémont Nyon 30/06/2017 Page 39 How to migrate data from MongoDB to Postgres with ToroDB