Sling Academy
Home/SQLite/Using SymmetricDS for Synchronizing SQLite Databases

Using SymmetricDS for Synchronizing SQLite Databases

Last updated: December 07, 2024

In today's increasingly distributed, mobile, and cloud-based software environments, database synchronization is a common requirement. When working with SQLite databases, sharing data across different devices and locations becomes necessary. Enter SymmetricDS, an open-source data replication and synchronization tool that can work wonders for SQLite database synchronization.

SymmetricDS offers a flexible and scalable solution for synchronizing data across a wide range of databases and systems. In this tutorial, we’ll explore how to use SymmetricDS to synchronize SQLite databases with detailed instructions and practical code examples.

Why Use SymmetricDS?

SymmetricDS supports more than 20 database systems, including SQLite. It provides:

  • Multimaster replication
  • Filter-based data routing
  • Transforms and enrichments of data during synchronization

Setting Up SymmetricDS

Begin by installing SymmetricDS. As it is Java-based, you'll need Java installed on your system. Download the SymmetricDS standalone package from the official website and extract it.

Configuration Steps

  1. Install Java:sudo apt-get install openjdk-8-jdk
  2. Download SymmetricDS: Unzip the downloaded package.wget https://sourceforge.net/projects/symmetricds/files/latest/download unzip SymmetricDS-.*.zip
  3. Setup the SymmetricDS Properties: Each node needs a properties file that defines its configuration.# Configuration for Node 1 engine.name=client symmetric.username=symmetric symmetric.password=symmetric sync.url=http://localhost:31415/sync/client

Configuring SQLite Databases

Now, let’s configure our SQLite databases. We will use two SQLite databases and set one as a "client" and the other as a "server".

Create Sample Databases

-- Server Database CREATE TABLE users (  user_id INTEGER PRIMARY KEY,  username TEXT NOT NULL,  password TEXT NOT NULL ); -- Client Database CREATE TABLE customers (  customer_id INTEGER PRIMARY KEY,  customer_name TEXT NOT NULL,  contact_email TEXT NOT NULL );

Synchronizing Data

Next, we execute the synchronization process. Start by launching the SymmetricDS engine for the client and server nodes.

Starting Synchronization Engine

  1. Server Node:./sym_admin --engine server start
  2. Client Node:./sym_admin --engine client start

Once both engines are running, SymmetricDS will monitor for changes in either database and apply the necessary updates to the other, ensuring both stay in sync.

Monitoring and Testing

Use the SymmetricDS admin tools to monitor activity and ensure proper synchronization.

Example of Monitoring Sync with Console:

./symadmin --engine server open-console

The admin console provides detailed logs and status of synchronizations allowing you to check which data has been synced, and any errors or warnings.

Summary

SymmetricDS provides a powerful, flexible, and easy-to-use tool for synchronizing SQLite databases across different nodes and environments. By following the steps outlined, developers can set up and use SymmetricDS effectively, enforcing robust data synchronization in applications that rely on distributed database architecture.

Next Article: Implementing Data Synchronization in Mobile Apps with SQLite

Previous Article: Overview of Popular Tools for SQLite Synchronization

Series: SQLite Data Synchronization

SQLite

You May Also Like

  • How to use regular expressions (regex) in SQLite
  • SQLite UPSERT tutorial (insert if not exist, update if exist)
  • What is the max size allowed for an SQLite database?
  • SQLite Error: Invalid Value for PRAGMA Configuration
  • SQLite Error: Failed to Load Extension Module
  • SQLite Error: Data Type Mismatch in INSERT Statement
  • SQLite Warning: Query Execution Took Longer Than Expected
  • SQLite Error: Cannot Execute VACUUM on Corrupted Database
  • SQLite Error: Missing Required Index for Query Execution
  • SQLite Error: FTS5 Extension Malfunction Detected
  • SQLite Error: R-Tree Node Size Exceeds Limit
  • SQLite Error: Session Extension: Invalid Changeset Detected
  • SQLite Error: Invalid Use of EXPLAIN Statement
  • SQLite Warning: Database Connection Not Closed Properly
  • SQLite Error: Cannot Attach a Database in Encrypted Mode
  • SQLite Error: Insufficient Privileges for Operation
  • SQLite Error: Cannot Bind Value to Parameter
  • SQLite Error: Maximum String or Blob Size Exceeded
  • SQLite Error: Circular Reference in Foreign Key Constraints