HA is a highly available SQLite cluster powered by an embedded NATS JetStream server. It provides distributed SQLite databases with replication, supporting multiple protocols for seamless integration.
- π Multiple Protocols: Connect via HTTP API, gRPC API, database/sql Go driver, JDBC driver, MySQL Wire Protocol, or PostgreSQL Wire Protocol
- π Replication: Use embedded or external NATS server for data replication
- π Read/Write Replicas: Create live local read/write replicas with go-ha database/sql driver
- π Read Replicas: Create live local read replicas with ha-sync SQLite extension
- π Change Data Capture (CDC): Supports CDC for real-time data streaming
- π Proxy: Proxy and replicate PostgreSQL or MySQL databases to the edge
- βοΈ Cluster Modes: Configure leader-based or leaderless clusters with custom conflict resolution strategies
- π Cross-Shard Queries: Execute queries across shards using SQL hints like
/*+ db=DSN */ - π Transaction Undo: Supports undo operations on committed transactions, allowing rollback to previous states
- π Full Documentation: https://litesql.github.io/ha/
Download the latest release from GitHub Releases.
Ensure you have Go 1.26+ installed.
go install github.com/litesql/ha@latestUsing a docker image:
docker run --name node1 \
-e HA_CREATE_DB_DIR=/data
-p 5432:5432 -p 8080:8080 -p 4222:4222 \
ghcr.io/litesql/ha:latest- Set up a volume at /data to store the NATS streams state and database files.
- Add litesql helm charts repository to Helm:
helm repo add litesql https://litesql.github.io/helm-charts- Update the chart repository:
helm repo update- Deploy ha to kubernetes:
helm install ha litesql/ha- Visit litesql helm charts repository to customize the installation;
mkdir db1
ha -n node1 --pg-port 5432 --mysql-port 3306 "file:db1/mydatabase.db"This starts:
- Embedded NATS server on port 4222
- MySQL Wire Protocol server on port 3306
- PostgreSQL Wire Protocol server on port 5432
- HTTP/gRPC API server on port 8080
mkdir db2
ha -n node2 --nats-port 0 -p 8081 --pg-port 5433 --mysql-port 3307 --replication-url nats://localhost:4222 "file:db2/mydatabase.db"This starts:
- PostgreSQL Wire Protocol server on port 5433
- MySQL Wire Protocol server on port 3307
- HTTP/gRPC API server on port 8081
It connects to the first instance's NATS server for replication.
Create a table and insert data:
ha -r http://localhost:8080
CREATE TABLE users(ID INTEGER PRIMARY KEY, name TEXT);
INSERT INTO users(name) VALUES('HA user');Verify replication by connecting to the second instance and querying the data.
ha -r http://localhost:8081
SELECT * FROM usersHA supports various command-line flags for configuration. Run ./ha --help for a complete list.
Key options:
-n, --name: Node name-p, --port: HTTP API port (default: 8080)--pg-port: PostgreSQL Wire Protocol port--mysql-port: MySQL Wire Protocol port--nats-port: NATS server port (0 to disable embedded server)--replication-url: NATS server URL for replication
For advanced configuration, see the full documentation.
Connect using the built-in HA client:
ha -r http://localhost:8080Special commands:
SHOW DATABASES;: List all databasesCREATE DATABASE dsn;: Create a new databaseDROP DATABASE id;: Drop a databaseSET DATABASE TO id;: Switch to a specific databaseUNSET DATABASE;: Use default databaseEXIT;: Quit client
HISTORY n: Retrieve transactions from sequence pointnUNDO n: Revert transactions from sequencenUNDOE n: Roll back entity modifications from sequencenUNDOT n: Revert transactions affecting entities from sequencen
Where n can be a sequence number or time duration (e.g., '5m').
PGPASSWORD=ha psql -h localhost -U ha -p 5432mysql -h localhost --port 3306 -u haHA can proxy connections to PostgreSQL, MySQL databases or any Debezium source connector database, replicating their data to achieve high availability and enable faster queries.
- HTTP API: https://litesql.github.io/ha/#5
- gRPC API: https://buf.build/litesql/sqlite-ha/sdks/main:grpc
- OpenAPI Spec: See
openapi.yamlin the repository or access http://localhost:8080/docs
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For major changes, please open an issue first to discuss the proposed changes.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

