Path: redb/redb.SQLite/README.md Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.SQLite/README.md ---- # redb.SQLite SQLite provider for **RedBase (REDB)** — Entity Database for .NET. [![NuGet](https://img.shields.io/nuget/v/redb.SQLite?label=NuGet&color=blue)](https://www.nuget.org/packages/redb.SQLite) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue)](../LICENSE) ## What's inside - SQLite-optimized SQL generation - Tree queries with recursive CTEs - Schema initialization (`redbPostgre.sql`) - Full LINQ-to-SQL translation - Depends on `redb.Core` and `Sqlite` ## Installation ```bash dotnet add package redb.SQLite ``` ## Setup ```csharp using redb.Core.Extensions; using redb.SQLite.Extensions; builder.Services.AddRedb(options => options .UseSqlite("Host=localhost;Port=5432;Database=mydb;Username=sqlite;Password=pass")); ``` ## Page cache and file mapping By default the provider leaves SQLite's own settings: a 2 MB page cache per connection and no memory-mapped file (`SqliteDataSource.MmapSizeBytes` and `SqliteDataSource.CacheSizeBytes` are 0). On a database of a few gigabytes that small cache is what most of a query's time goes into. The examples set both before the provider is registered: ```csharp using redb.SQLite.Data; SqliteDataSource.MmapSizeBytes = 4L * 1024 * 1024 * 1024; // PRAGMA mmap_size SqliteDataSource.CacheSizeBytes = 64L * 1024 * 1024; // PRAGMA cache_size, per connection ``` Measured on the examples database (2.5 GB, about 100 000 employees), one grouping over a nested array with a window took 940-1060 ms with the defaults and 430-600 ms with these two settings. The trade-off: a mapping takes address space, not memory of its own; the pages live in the operating system's file cache and all connections share them. SQLite caps the mapping at its compile-time limit, and what lies beyond the mapped part is read as before. The page cache is process memory, and every pooled connection has its own, so 64 MB times the number of open connections. For a small database, or where memory is tight, keep the defaults. ## Planner statistics SQLite keeps no statistics of its own until `ANALYZE` runs, and without them it may start a query from a large table where a small page should drive it. At start-up the provider analyzes a file that has none and holds at least 10 000 value rows (sampled by `MaintenanceAnalysisLimit`, 1 000 rows per index by default), and runs `PRAGMA optimize` on a file that has them, which refreshes only tables that grew a lot. A file filled by a bulk import gets its statistics at the next start; `IMaintenanceProvider.AnalyzeAsync` gathers them on demand. `KeepSqlitePlannerStatistics = false` turns the start-up step off. ## Several processes on one file Several processes may open the same database file; SQLite runs their writes one at a time, and redb never hands out an object id twice. One case stays with the application: an id it takes itself (`NextObjectIdBatchAsync`) inside a transaction that then rolls back may go to another process before it is used, so take such ids again after a rollback. ## Links - Documentation (EN): [redbase.app](https://redbase.app) - Documentation (RU): [redb.ru](https://redb.ru) - API Reference: [redbase-app.github.io/redb](https://redbase-app.github.io/redb/) - GitHub: [github.com/redbase-app/redb](https://github.com/redbase-app/redb) ## License Apache License 2.0 — see [LICENSE](https://github.com/redbase-app/redb/blob/main/LICENSE).