ha

command module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

README ΒΆ

ha

License LiberaPay receives patrons

Highly available leaderless SQLite cluster

Powered by an embedded NATS JetStream server.

Features

  • πŸ”Œ Connect via HTTP API, MySQL or PostgreSQL Wire Protocol
  • πŸ” Replicate data using embedded or external NATS server
  • πŸ“ Create live local read/write replicas with go-ha database/sql driver
  • πŸ“š Create live local read replicas with ha-sync SQLite extension
  • πŸ”„ Supports Change Data Capture (CDC)
  • βš™οΈ Configure custom strategies for resolving replication data conflicts
  • πŸ“– Full documentation: https://litesql.github.io/ha/

πŸš€ Getting Started

Download and install the latest release

1. Start the first ha instance
mkdir db1
ha -n node1 "file:db1/mydatabase.db?_journal=WAL&_busy_timeout=5000"

This command launches:

  • An embedded NATS server on port 4222
  • A PostgreSQL Wire Protocol server on port 5432
  • An HTTP API server on port 8080
2. Start a second ha instance
mkdir db2
ha -n node2 -p 8081 --nats-port 0 --pg-port 5433 --mysql-port 3306 --replication-url nats://localhost:4222 "file:db2/mydatabase.db?_journal=WAL&_busy_timeout=5000"

This command starts:

  • A PostgreSQL Wire Protocol server on port 5433
  • A MySQL Wire Protocol server on port 3306
  • An HTTP API server on port 8081.

It connects to the previously launched embedded NATS server for replication.

3. Connect using a PostgreSQL client
PGPASSWORD=ha psql -h localhost -U ha

Create and populate a table:

CREATE TABLE users(ID INTEGER PRIMARY KEY, name TEXT);
INSERT INTO users(name) VALUES('HA user');
4. Verify replication on the second instance
PGPASSWORD=ha psql -h localhost -U ha -p 5433
SELECT * FROM users;
 ID |  name   
----+---------
 1  | HA user

Using a mysql client:

mysql -h localhost --port 3306 -u root

MySQL [(none)]> show databases;
+-----------------------+
| Database              |
+-----------------------+
| file:/ha.db?vfs=memdb |
+-----------------------+
1 row in set (0,000 sec)

MySQL [(none)]> use file:/ha.db?vfs=memdb

MySQL [file:/ha.db?vfs=memdb]> select * from users;
+----+---------+
| ID | name    |
+----+---------+
|  1 | HA user |
+----+---------+
1 row in set (0,000 sec)
5. Please refer to the complete documentation for the HTTP API

HTTP API

πŸ› οΈ License & Contributions

This project is open-source. Contributions, issues, and feature requests are welcome via GitHub.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL