rqlite — Distributed Database Built on SQLite & Raft
Lightweight distributed relational database that replicates SQLite across nodes using the Raft consensus protocol.
先审查再安装
这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。
npx -y tokrepo@latest install 44ddef49-3931-11f1-9bc6-00163e2b0d79 --target codex先 dry-run,确认写入项后再运行此命令。
What it is
rqlite turns the battle-tested SQLite engine into a fault-tolerant distributed database. Each node wraps SQLite with the Raft consensus protocol, replicating writes to a cluster of 3, 5, or 7 nodes. It serves SQL over a simple HTTP/JSON API plus a native command-line shell.
rqlite is ideal when you want relational guarantees and easy operations without the complexity of running PostgreSQL or MySQL clusters. It ships as a tiny single-binary with no external dependencies.
How it saves time or tokens
rqlite provides distributed SQL without the operational complexity of traditional database clusters. Starting a cluster takes three commands. Adding nodes requires a single join command. There is no external dependency (no ZooKeeper, no etcd). The HTTP/JSON API works with any language that can make HTTP requests, eliminating the need for database-specific drivers. Read consistency levels (none, weak, strong, linearizable) let you trade consistency for performance per request.
How to use
- Start a 3-node cluster:
rqlited -node-id 1 -http-addr localhost:4001 \
-raft-addr localhost:4002 ~/node1 &
rqlited -node-id 2 -http-addr localhost:4003 \
-raft-addr localhost:4004 -join http://localhost:4001 ~/node2 &
rqlited -node-id 3 -http-addr localhost:4005 \
-raft-addr localhost:4006 -join http://localhost:4001 ~/node3 &
- Write and read over HTTP:
curl -XPOST localhost:4001/db/execute \
-d '[["CREATE TABLE foo (id INTEGER PRIMARY KEY, name TEXT)"]]'
curl -XPOST localhost:4001/db/execute \
-d '[["INSERT INTO foo(name) VALUES(?)", "bar"]]'
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo'
- Check cluster status:
curl localhost:4001/status?pretty
Example
Using rqlite with different read consistency levels:
# No consistency check (fastest, may read stale data)
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo' \
--data-urlencode 'level=none'
# Weak consistency (confirms leader, no log check)
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo' \
--data-urlencode 'level=weak'
# Strong consistency (verifies with Raft quorum)
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo' \
--data-urlencode 'level=strong'
Related on TokRepo
- Database tools — More database tools on TokRepo.
- Self-hosted tools — Browse lightweight self-hosted infrastructure.
Common pitfalls
- Running a single-node rqlite cluster in production provides no fault tolerance. Deploy at least 3 nodes for automatic leader election and failover.
- rqlite is not designed for high-throughput write workloads. Raft consensus adds latency to every write. Use it for configuration stores, metadata, and low-to-moderate write volumes.
- SQLite limitations apply: no concurrent writers per node, limited data types, no stored procedures. rqlite inherits all SQLite constraints.
常见问题
Raft is a consensus algorithm that ensures all nodes in a cluster agree on the same data. One node is elected leader, and writes are replicated to a majority of nodes before being committed. If the leader fails, a new leader is elected automatically.
SQLite is a single-file embedded database. rqlite wraps SQLite with Raft consensus to replicate data across multiple nodes, providing fault tolerance and a network-accessible HTTP API. rqlite adds distribution; SQLite provides the storage engine.
rqlite uses an HTTP/JSON API rather than the MySQL or PostgreSQL wire protocols. There are client libraries for Go, Python, and JavaScript that wrap the HTTP API. Standard SQL drivers for other databases will not work.
rqlite offers four read consistency levels: none (fastest, may be stale), weak (confirms current leader), strong (Raft quorum verification), and linearizable (strongest, single-value semantics). Choose per query based on your requirements.
Run an odd number of nodes (3, 5, or 7). A 3-node cluster tolerates 1 failure. A 5-node cluster tolerates 2. More nodes increase read capacity but add write latency due to Raft replication.
引用来源 (3)
- rqlite GitHub— rqlite distributed database on SQLite and Raft
- rqlite Docs— rqlite documentation and API reference
- Raft Paper— Raft consensus algorithm
讨论
相关资产
OceanBase — Distributed SQL Database for Enterprise Workloads
Scalable distributed relational database supporting both OLTP and OLAP with MySQL and Oracle compatibility, built for financial-grade reliability.
CrateDB — Distributed SQL Database for Machine Data
CrateDB is a distributed SQL database optimized for machine data, IoT, and time-series workloads. Built on a shared-nothing architecture, it combines the familiarity of SQL with the scalability of a distributed columnar store for real-time analytics on large datasets.
Apache ShardingSphere — Distributed Database Middleware Ecosystem
A guide to Apache ShardingSphere, the distributed database middleware that provides data sharding, read-write splitting, encryption, and shadow database capabilities.
Apache CouchDB — Seamless Multi-Master Sync Database
Apache CouchDB is a document-oriented NoSQL database that uses JSON for documents, JavaScript for queries, and HTTP for its API. Its signature feature is multi-master replication, enabling offline-first applications that sync reliably across distributed nodes.