Skip to content

litesql/go-ha

Repository files navigation

go-ha

Go database/sql base driver providing high availability for SQLite databases.

Features

  • High availability support for SQLite databases.
  • Replication: Synchronize data across nodes using NATS.
  • Customize the replication strategy
  • Leaderless clusters: Read/Write from/to any node. Last-writer wins by default, but you can customize conflict resolutions by implementing ChangeSetInterceptor.
  • Leader-based cluster: Write operations are redirected to the leader to prevent conflicts entirely.
  • Embedded or External NATS: Choose between an embedded NATS server or an external one for replication.
  • Easy to integrate with existing Go projects.

Drivers

Options

DSN Param Description Default
asyncPublisher Enables asynchronous publishing of replication events. false
asyncPublisherOutboxDir Directory to store outbox files for asynchronous publishing.
autoStart Automatically starts the subscriber and snapshotter when the node is initialized. true
replicationID Replication ID [database filename]
deliverPolicy Specifies the delivery policy for replication events. Options include all, last, etc. all
disableSubscriber Disables the subscriber for replication. false
disablePublisher Disables the publisher for replication. false
disableDBSnapshotter Disables the database snapshotter used for initial synchronization. false
disableDDLSync Disables the synchronization of DDL (Data Definition Language) changes across nodes. false
grpcInsecure Insecure gRPC connections false
grpcPort TCP port for the gRPC server
grpcTimeout Timeout for the gRPC operations 5s
grpcToken Token to protect gRPC server
leaderProvider Defines the strategy for determining a leader node in the cluster. This is useful for redirecting HTTP requests. Examples include dynamic:http://host:port or static:http://host:port.
name Name of the node in the cluster.
natsConfigFile Path to the configuration file for the embedded NATS server. Overrides others NATS configurations.
natsName Sets the name of the embedded NATS server.
natsPort Configures the port for the embedded NATS server. 4222
natsStoreDir Directory to store data for the embedded NATS server.
publisherTimeout Timeout duration for publishing replication events. 15s
replicationStream Name of the replication stream used for synchronizing data.
replicationURL URL used for connecting to the replication stream.
replicas Number of replicas to maintain for high availability. 1
rowIdentify Row identify strategy: pk, rowid or full pk
snapshotInterval Interval for taking database snapshots. 1m
streamMaxAge Maximum age of messages in the replication stream before they are removed.

Projects using go-ha

  • HA: Highly available leaderless SQLite cluster with HTTP and PostgreSQL Wire Protocol
  • PocketBase HA: Highly available leaderless PocketBase cluster
  • sqlc-http: Generate net/http go server from SQL

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Go database/sql driver

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages