Storage Management
The Storage module governs where Smart SCADA persists data. It separates metadata (in SQLite) from time-series telemetry (in InfluxDB) and provides operational tooling for backup, restore, and cleanup.
Interface Screenshot

Captured from the live Smart Site system with the English UI. See the
zh-CNcounterpart for the Chinese-UI screenshot.
1. Storage Architecture
| Store | Technology | Purpose | Location |
|---|---|---|---|
| Global | SQLite | Users, roles, menus, system config | ss-run/ss/data/db/ss-node.db |
| Project | SQLite | Devices, tags, alarms, scripts per project | {PROJECTS_DIR}/{name}/db/system.db |
| Time-series | InfluxDB 2 | Telemetry points, historical values | InfluxDB bucket per project |
| Cache | In-memory | Latest data point per tag for fast reads | DataPointCacheService |
InfluxDB is shipped as a base service under ss-run/ss/base_services/influxdb2-2.7.8/.
2. SQLite Metadata Storage
2.1 Global Database
The global DB holds cross-project metadata:
sys_users,sys_roles,sys_positionssys_menussystem_configs(key-value)audit_logs
It is opened by the TypeORM DataSource configured in ss-node/src/data-source.ts.
2.2 Project Databases
When PROJECT_DB_MODE=isolated, each project gets its own SQLite file with operational tables:
devices,device_groups,device_authorizationsdata_tagsalarms,alarm_groupsscripts,script_executionspages(configuration screens)
The connection is lazily opened on first access to the project and pooled for the lifetime of the request.
2.3 Migrations
TypeORM migrations live under ss-node/src/migrations/ and run on startup:
1700000000000-InitialSchema.ts1700100000000-AddDataTagsTable.ts1700200000000-AddScriptsAndExecutionsTables.ts1700300000000-AddAuditLogsAndSystemTables.ts1700400000000-AddPagesTable.ts
New deployments apply them automatically; existing deployments receive incremental schema changes through these migrations.
3. InfluxDB Time-Series Storage
3.1 Configuration
InfluxDB connection settings are stored in the project's projectinfo.json and in system config:
- URL (default
http://localhost:8086) - Organization
- Token
- Bucket (one per project recommended)
The @ss-node/ss-storage-influx package wraps the InfluxDB client and exposes write/query helpers used by the PersistStep.
3.2 Writing Points
The pipeline's persist.step.ts writes a data point to InfluxDB after the deadband filter:
measurement = "tag_data"
tags: { deviceId, tagId, quality }
fields: { value }
timestamp: read timestamp
3.3 Querying History
Historical queries (used by the device detail History tab and reports) call InfluxDB's Flux API through the backend, which returns aggregated or raw series.
4. Data Archival Policies
To keep InfluxDB performant, define retention and archival policies:
- Retention — InfluxDB bucket retention period (e.g. 30d for raw, 1y for downsampled)
- Downsampling — a scheduled Flux task aggregates raw data into a longer-interval bucket
- Cold archival — export older data to CSV/Parquet and delete from InfluxDB
Configure retention per bucket in the InfluxDB admin UI or via the influx.exe CLI shipped with the base service.
5. Database Operations
The System → Database Ops page exposes operational actions:
| Action | Description |
|---|---|
| Backup | Snapshot the current SQLite DB(s) to a .db file |
| Restore | Replace the current DB from a backup file |
| Cleanup | Purge old alarm events, audit logs, or script executions |
| Vacuum | Reclaim SQLite free space |
| Influx Backup | Trigger InfluxDB backup via the bundled backup.bat |
5.1 Using the Bundled Scripts
The InfluxDB base service ships helper scripts:
backup.bat— back up all buckets to a directoryrestoredb.bat— restore buckets from a backup directoryiot-influxdb.bat— start InfluxDB with the project config
Run these from ss-run/ss/base_services/influxdb2-2.7.8/.
6. FAQ
Q: SQLite database is locked errors appear.
A: This usually means another process holds a write lock. Ensure only one backend instance accesses the same DB file. If it persists, run VACUUM from the Database Ops page.
Q: InfluxDB queries are slow. A: Check the bucket retention and consider downsampling. Verify the time range is bounded — unbounded queries scan the whole bucket. Add tag indexes for commonly filtered tags.
Q: How much disk space does a project need? A: Metadata is small (a few MB). Time-series storage dominates: estimate ~50 bytes per point × points per second × retention period. A 100-tag project at 1 Hz for 30 days is ~13 GB.
Q: Can I use PostgreSQL instead of SQLite?
A: The TypeORM entities are database-agnostic, but the deployment is tested with SQLite. Switching requires updating the DataSource config and re-running migrations.
7. Related Links
../../02-project/README.md../../03-device/device-detail.md../../../../../../../docs/03-架构设计/后端-数据库设计.md- InfluxDB Base Service