Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronize Postgres Server Database to Sqllite Client database

I am trying to create an app that receives an Sqlite database from a server for offline use but cloud synchronization. The server has a postgres database with information from many clients.

1) Is it better to delete the sql database and create a new one from a query, or try to synchronize and update the existing separate sqlite files (or another better solution). The refreshes will be a few times a day per client.

2) if it is the latter, could you give me any leads to resources on how I could do this?

I am pretty new to database applications so please excuse my ignorance and let me know if there is any way I could clarify.

like image 403
ThinkBonobo Avatar asked Aug 09 '13 16:08

ThinkBonobo


2 Answers

There is no one size fits all approach here. You need to carefully consider exactly what needs to be done, what you are replicating, how much data is involved, and what your write models are, all before you build a solution. Along the way you have to decide how to handle write conflicts and more.

In general the one thing I would say is that such synchronization works best with append-only write models (i.e. inserts, no deletes, no updates), and one way to do it is to log changes that need to be made and replicate those changes.

However, master-master replication is difficult on the best of days and with the best of tools available. Jumping between databases with very different capabilities will introduce a number of additional problems. You are in for a big job.

like image 58
Chris Travers Avatar answered Nov 16 '22 06:11

Chris Travers


Here's an open source product that claims to solve this for many database types including Postgres. I have no affiliation or commercial interest in this company.

  • https://github.com/sqlite-sync/SQLite-sync.com
  • http://sqlite-sync.com/

If you're able and willing to step outside relational databases to use an object store you might want to have a look at CouchDb and perhaps PouchDb that use a MVCC based replication protocol designed to support multi-master replication including conflict resolution. Under the covers, PouchDb uses adaptors for Sqlite, IndexDb, Local storage or a remote CouchBb instance to persist client side data. It auto selects the best client side storage option for the given desktop or mobile browser. The Sqlite engine can be either WebSQL or a Cordova Sqlite plugin.

  • http://couchdb.apache.org/
  • https://pouchdb.com/
like image 34
Tony O'Hagan Avatar answered Nov 16 '22 06:11

Tony O'Hagan