LiteGraph uses provider-neutral database settings while keeping SQLite as the default zero-configuration backend.
The current implementation supports SQLite execution through the repository factory and includes an executable PostgreSQL provider backed by NpgsqlDataSource.
Default database settings:
{
"LiteGraph": {
"Database": {
"Type": "Sqlite",
"Filename": "litegraph.db",
"InMemory": false,
"Hostname": "localhost",
"Port": null,
"DatabaseName": "litegraph",
"Username": null,
"Password": null,
"Schema": "litegraph",
"ConnectionString": null,
"MaxConnections": 32,
"CommandTimeoutSeconds": 30
}
}
}The legacy LiteGraph.GraphRepositoryFilename setting is still supported. Setting it updates the SQLite filename in LiteGraph.Database.Filename.
SQLite is the default backend:
{
"LiteGraph": {
"Database": {
"Type": "Sqlite",
"Filename": "litegraph.db",
"InMemory": false
}
}
}For a temporary in-memory repository:
{
"LiteGraph": {
"Database": {
"Type": "Sqlite",
"Filename": "litegraph.db",
"InMemory": true
}
}
}SQLite is appropriate for local development, tests, embedded deployments, and small single-process deployments.
Server startup applies these environment variables after reading litegraph.json:
| Variable | Setting |
|---|---|
LITEGRAPH_DB_TYPE |
LiteGraph.Database.Type |
LITEGRAPH_DB |
LiteGraph.GraphRepositoryFilename |
LITEGRAPH_DB_FILENAME |
LiteGraph.GraphRepositoryFilename |
LITEGRAPH_DB_HOST |
LiteGraph.Database.Hostname |
LITEGRAPH_DB_PORT |
LiteGraph.Database.Port |
LITEGRAPH_DB_NAME |
LiteGraph.Database.DatabaseName |
LITEGRAPH_DB_USERNAME |
LiteGraph.Database.Username |
LITEGRAPH_DB_PASSWORD |
LiteGraph.Database.Password |
LITEGRAPH_DB_SCHEMA |
LiteGraph.Database.Schema |
LITEGRAPH_DB_CONNECTION_STRING |
LiteGraph.Database.ConnectionString |
LITEGRAPH_DB_MAX_CONNECTIONS |
LiteGraph.Database.MaxConnections |
LITEGRAPH_DB_COMMAND_TIMEOUT_SECONDS |
LiteGraph.Database.CommandTimeoutSeconds |
LITEGRAPH_TRANSACTION_MAX_OPERATIONS |
LiteGraph.Transactions.MaxOperations |
LITEGRAPH_TRANSACTION_MAX_TIMEOUT_SECONDS |
LiteGraph.Transactions.MaxTimeoutSeconds |
LITEGRAPH_DB and LITEGRAPH_DB_FILENAME are aliases for the SQLite filename. LITEGRAPH_DB takes precedence when both are set.
Embedded callers can create repositories through GraphRepositoryFactory:
using LiteGraph;
using LiteGraph.GraphRepositories;
DatabaseSettings settings = new DatabaseSettings
{
Type = DatabaseTypeEnum.Sqlite,
Filename = "litegraph.db"
};
using GraphRepositoryBase repository = GraphRepositoryFactory.Create(settings);
using LiteGraphClient client = new LiteGraphClient(repository);
client.InitializeRepository();The factory returns SqliteGraphRepository for DatabaseTypeEnum.Sqlite and PostgresqlGraphRepository for DatabaseTypeEnum.Postgresql.
The embedded C# SDK surface uses the same public storage model. DatabaseSettings, DatabaseTypeEnum, and GraphRepositoryFactory are the supported storage configuration API for in-process callers. There is no separate storage-admin REST model in this release because the running server's provider is selected at startup and is not mutable through an authenticated admin route.
PostgreSQL is the recommended production backend. The configuration shape is:
{
"LiteGraph": {
"Database": {
"Type": "Postgresql",
"Hostname": "postgres.example.internal",
"Port": 5432,
"DatabaseName": "litegraph",
"Username": "litegraph",
"Password": "use-a-secret-manager",
"Schema": "litegraph",
"MaxConnections": 32,
"CommandTimeoutSeconds": 30
}
}
}Or with a connection string:
{
"LiteGraph": {
"Database": {
"Type": "Postgresql",
"ConnectionString": "Host=postgres.example.internal;Port=5432;Database=litegraph;Username=litegraph;Password=..."
}
}
}Use a dedicated PostgreSQL database and schema for LiteGraph. Before production deployment, run the PostgreSQL provider suite by setting LITEGRAPH_TEST_POSTGRESQL_CONNECTION_STRING against a disposable test database.
PostgreSQL supports:
- schema creation and indexes in the configured schema
- tenants, users, credentials, graphs, nodes, edges, labels, tags, vectors, request history, authorization audit, authorization roles, batch, vector index metadata, and admin repository methods
- graph-scoped transactions
- JSON data filters through PostgreSQL
jsonbextraction, including numeric and boolean comparisons - pooled concurrent writes through
NpgsqlDataSource - synchronous and asynchronous repository initialization/disposal
The checked-in Docker deployment in docker/compose.yaml is PostgreSQL-backed by default. It starts a postgresql service, runs a one-shot litegraph-postgresql-init service, and injects the matching LiteGraph settings into the init and server containers with LITEGRAPH_DB_* environment variables.
Default local Docker values:
| Setting | Default |
|---|---|
| Host PostgreSQL port | 15432 |
| Compose PostgreSQL host | postgresql |
| Database | litegraph |
| Username | litegraph |
| Password | litegraph |
| Schema | litegraph |
| Data volume | postgresql-data |
Startup order:
postgresqlstarts and creates the configured database fromPOSTGRES_DBwhen the volume is new.litegraph-postgresql-initwaits for PostgreSQL health, runsLiteGraph.Server --init-only, creates the configured schema and tables through the repository setup path, seeds built-in authorization roles, createsdefault@user.com/passwordand bearer tokendefault, and creates a starter graph with nodes and edges when the default graph is empty.litegraphstarts only after the init service exits successfully.- MCP, dashboard, Prometheus, and Grafana wait on the long-running LiteGraph service.
Override sample Docker values with:
| Variable | Purpose |
|---|---|
LITEGRAPH_POSTGRESQL_HOST_PORT |
Host port published for PostgreSQL |
LITEGRAPH_POSTGRESQL_DATABASE |
PostgreSQL database name |
LITEGRAPH_POSTGRESQL_USERNAME |
PostgreSQL username |
LITEGRAPH_POSTGRESQL_PASSWORD |
PostgreSQL password |
LITEGRAPH_POSTGRESQL_SCHEMA |
LiteGraph schema inside the database |
LITEGRAPH_DB_MAX_CONNECTIONS |
LiteGraph PostgreSQL pool size |
LITEGRAPH_DB_COMMAND_TIMEOUT_SECONDS |
LiteGraph database command timeout |
The mounted docker/litegraph.json and docker/factory/litegraph.json also use Type = Postgresql, Hostname = postgresql, and the sample credentials so factory reset preserves the PostgreSQL-backed deployment. For SQLite Docker experiments, change the JSON or override LITEGRAPH_DB_TYPE=Sqlite and set a SQLite filename.
Use this checklist before promoting PostgreSQL-backed LiteGraph to production:
- Create a dedicated database, schema, and database user for LiteGraph. The LiteGraph user needs ownership of the configured schema so repository initialization can create and update tables and indexes.
- Store
LITEGRAPH_DB_CONNECTION_STRINGorLITEGRAPH_DB_PASSWORDin a secret manager. Do not place passwords in source-controlledlitegraph.jsonfiles. - Require TLS for networked PostgreSQL traffic when LiteGraph and PostgreSQL do not run on the same trusted host or private network.
- Set
LITEGRAPH_DB_MAX_CONNECTIONSbelow the PostgreSQL server's available connection budget after accounting for other applications, migrations, monitoring, and administrative sessions. - Tune
LITEGRAPH_DB_COMMAND_TIMEOUT_SECONDSfor expected graph query and transaction workloads. Keep the serverSettings.RequestTimeoutSecondsgreater than or equal to the database command timeout unless a shorter HTTP timeout is intentional. - Tune
LITEGRAPH_TRANSACTION_MAX_OPERATIONSandLITEGRAPH_TRANSACTION_MAX_TIMEOUT_SECONDSfor the largest graph transaction workload the server should accept. REST transaction requests are capped by these values before execution. - Run
dotnet run --project src/Test.Automated/Test.Automated.csproj --framework net10.0withLITEGRAPH_TEST_POSTGRESQL_CONNECTION_STRINGpointed at a disposable PostgreSQL database during release validation. - Enable regular PostgreSQL backups and test restore into a disposable database before switching production traffic.
- Monitor
/metricsforlitegraph_storage_backend_info, repository operation counts, repository operation durations, HTTP errors, graph query errors, transaction rollbacks, andlitegraph.vector.index.mutation.failures. - Keep PostgreSQL autovacuum enabled. Schedule
VACUUM ANALYZEaccording to write volume if operational monitoring shows bloat or stale plans. - Rebuild file-backed vector indexes after restoring or migrating database content if vector index files were not restored with the database.
- For high-availability deployments, place LiteGraph behind a process supervisor or orchestrator and use PostgreSQL-managed failover. LiteGraph does not implement database failover orchestration itself.
- Re-run provider verification after PostgreSQL major-version upgrades, schema migrations, or connection-string changes.
SQLite tests run by default. The PostgreSQL provider suite is registered in Test.Shared but skips unless a dedicated test database is configured through an environment variable:
LITEGRAPH_TEST_POSTGRESQL_CONNECTION_STRING
This value is intentionally a connection string so test runners do not need to print or assemble credentials. When the variable is absent, the test is reported as skipped with a reason. When the PostgreSQL variable is present, the suite initializes PostgreSQL storage and runs a live provider smoke covering core CRUD, JSON data filtering, concurrent writes, and graph transaction commit/rollback.
DatabaseSettings.ToSafeString() redacts:
PasswordConnectionString
Do not log raw settings objects or connection strings from application code.
LiteGraph includes provider-neutral migration and verification helpers in LiteGraph.Storage.StorageMigrationManager.
Example SQLite-to-PostgreSQL migration:
using LiteGraph;
using LiteGraph.Storage;
DatabaseSettings source = new DatabaseSettings
{
Type = DatabaseTypeEnum.Sqlite,
Filename = "litegraph.db"
};
DatabaseSettings destination = new DatabaseSettings
{
Type = DatabaseTypeEnum.Postgresql,
ConnectionString = "Host=postgres.example.internal;Port=5432;Database=litegraph;Username=litegraph;Password=..."
};
StorageMigrationResult result = await StorageMigrationManager.MigrateAsync(
source,
destination,
verify: true,
sampleSize: 25);
if (!result.Succeeded)
{
foreach (string difference in result.Verification.Differences)
Console.WriteLine(difference);
}The migration path copies tenants, users, credentials, graphs, nodes, edges, labels, tags, vectors, custom authorization roles, user role assignments, and credential scope assignments. Destination repositories are initialized before import, so PostgreSQL built-in roles are seeded and source built-in role references are mapped to destination built-in roles by name.
Verification compares entity counts and sampled source GUIDs in the destination. The recommended production sequence is:
- stop writes to the SQLite deployment
- run
StorageMigrationManager.MigrateAsyncfrom SQLite to PostgreSQL with verification enabled - review
StorageMigrationResult.Verification.Differences - start LiteGraph with
Database.Type = Postgresql - rebuild vector indexes if the deployment uses file-backed vector indexes and the index files were not copied with the database
LiteGraph v7.0 uses HnswLite 2.0.1 for HNSW vector indexes. HnswSqlite index artifacts written by v7.0 include FormatVersion = 2, HnswLiteVersion = "2.0.1", vector metadata, layer assignments, and persisted neighbor connections. The neighbor connection data is required for reload-safe indexed search after process restart.
When migrating storage providers, restoring backups, or upgrading from earlier LiteGraph builds, treat file-backed HNSW index files as derived artifacts. Back up indexes/, but prefer rebuilding indexes from persisted vectors unless the artifact is known to be v7.0 format. If an existing index file lacks FormatVersion = 2, rebuild it with client.Graph.RebuildVectorIndex(...), client.VectorIndex.RebuildVectorIndex(...), or POST /v2.0/tenants/{tenantGuid}/graphs/{graphGuid}/vectorindex/rebuild before relying on indexed search results.
- SQLite and PostgreSQL are implemented providers.
- Provider-specific query generation is normalized for SQLite and PostgreSQL.
- Provider-neutral migration copies repository data but does not perform online dual-write cutover or external backup orchestration.
- PostgreSQL provider coverage runs through the live provider suite when
LITEGRAPH_TEST_POSTGRESQL_CONNECTION_STRINGis configured.