Owner: AidenHeavensXD
MoodengSQL is a blazing-fast, PostgreSQL-inspired relational database engine written in Rust. It speaks a subset of the PostgreSQL wire protocol and SQL dialect, optimized for low-latency reads and writes.
- PostgreSQL-compatible SQL —
CREATE TABLE,INSERT,SELECT,UPDATE,DELETE,CREATE INDEX - PostgreSQL wire protocol — connect with the built-in CLI or any compatible client
- B-tree indexes — fast point lookups and range scans
- Binary persistence — durable on-disk storage with bincode serialization
- Metadata persistence — schema and indexes survive server restart (
meta.bin) - WAL + checkpoint — write-ahead log with automatic checkpointing (every 50 ops)
- Batch WAL fsync — groups disk sync every 10 ops for higher write throughput
- Transactions —
BEGIN/COMMIT/ROLLBACKwith undo log - Index scan —
SELECT ... WHERE col = valueuses B-tree index when available - ORDER BY / LIMIT / OFFSET — sorted and paginated queries
- INNER JOIN — multi-table queries with
ONclause - GROUP BY —
COUNT,SUM,AVG,MIN,MAXaggregates - Extended protocol — Parse/Bind/Execute for parameterized queries (
$1,$2) - EXPLAIN — query plan shows Index Scan vs Seq Scan
- Table-level locking — concurrent connections with read/write locks
- Constraints — PRIMARY KEY (auto-index) and NOT NULL enforcement
- Data validation —
moodengsql --checkverifies catalog/storage consistency - Configuration —
moodeng.tomlfor server, storage, and logging - Backup / restore — gzip tar archives of the data directory
- Health check —
moodengsql pingfor load balancers and Docker - Docker — Dockerfile and docker-compose for container deployment
- CI — GitHub Actions runs tests and release builds
- Concurrent catalog — lock-free table metadata via DashMap
- Rich types — INT4, INT8, FLOAT4, FLOAT8, TEXT, VARCHAR, BOOL, TIMESTAMP, JSON
# Build everything
cargo build --release
# Start the server (default port 5432)
./target/release/moodengsql --data-dir ./moodeng_data
# Connect with the CLI (in another terminal)
./target/release/moodengCREATE TABLE users (
id INT PRIMARY KEY,
name TEXT NOT NULL,
email TEXT
);
INSERT INTO users VALUES (1, 'Alice', 'alice@moodeng.dev');
INSERT INTO users VALUES (2, 'Bob', 'bob@moodeng.dev');
SELECT * FROM users WHERE id = 1;
CREATE INDEX idx_users_email ON users (email);
UPDATE users SET email = 'alice@sql.dev' WHERE id = 1;
DELETE FROM users WHERE id = 2;moodengsql/
├── moodeng-core/ # Storage engine, B-tree indexes, SQL executor
├── moodeng-server/ # Async TCP server (PostgreSQL wire protocol)
└── moodeng-cli/ # Interactive command-line client
| Component | Technology | Purpose |
|---|---|---|
| SQL Parser | sqlparser (PostgreSQL dialect) | Parse incoming SQL |
| Storage | bincode + fsync | Durable row persistence |
| Indexes | BTreeMap | O(log n) lookups |
| Catalog | DashMap | Concurrent schema metadata |
| Server | tokio | Async connection handling |
MoodengSQL uses subcommands for operations. Legacy flat flags still work for serve:
# Start server (subcommand or legacy)
moodengsql serve --data-dir ./moodeng_data
moodengsql --data-dir ./moodeng_data --port 5432
# With config file
moodengsql serve --config moodeng.toml
# Validate data directory
moodengsql check --data-dir ./moodeng_data
# Backup and restore
moodengsql backup --output backup.tar.gz --data-dir ./moodeng_data
moodengsql restore --from backup.tar.gz --data-dir ./moodeng_data
# Health check
moodengsql ping --host 127.0.0.1 --port 5432Copy moodeng.toml.example to moodeng.toml to customize host, port, data directory, and log level.
docker compose up -d --build
docker compose exec moodengsql moodeng ping --config /etc/moodengsql/moodeng.tomlData is persisted in the moodeng_data Docker volume at /data.
cargo run --release --example benchmark -p moodeng-corePrints insert and indexed point-select throughput for a quick sanity check.
moodeng [OPTIONS]
Options:
-h, --host <HOST> Server host [default: 127.0.0.1]
-p, --port <PORT> Server port [default: 5432]
-c, --command <CMD> Execute a single SQL command and exit
MoodengSQL prioritizes speed through:
- In-memory row cache with lazy disk persistence
- B-tree indexes for indexed column access instead of full scans
- Zero-copy value serialization where possible
- Lock-free concurrent catalog for multi-connection workloads
- Async I/O with tokio for non-blocking connection handling
MIT — Copyright (c) 2026 AidenHeavensXD