Overview
FreeTAKServer uses SQLAlchemy ORM for database operations with support for SQLite and MySQL. The database stores:- User information and authentication
- Cursor on Target (CoT) events
- Data packages
- Video streams
- Emergency notifications
- Federation configurations
- ExCheck checklists
- API users and access logs
Database Configuration
Database settings are managed through theDatabaseConfiguration class located in FreeTAKServer/core/configuration/DatabaseConfiguration.py.
Database Type
Database engine to use. Supported values:
SQLite, MySQLEnvironment variable: FTS_DATABASE_TYPEYAML: System.FTS_DATABASE_TYPEDatabase Path
Path to the database file (SQLite) or connection details (MySQL)Environment variable:
FTS_DB_PATHYAML: Filesystem.FTS_DB_PATHCoT Database Storage
Whether to save Cursor on Target (CoT) messages to the databaseEnvironment variable:
FTS_COT_TO_DBYAML: Filesystem.FTS_COT_TO_DBConnection Strings
TheDatabaseConfiguration class automatically generates SQLAlchemy connection strings based on the database type.
SQLite Configuration
MySQL Configuration
YAML Configuration:Database Controller
TheDatabaseController class (FreeTAKServer/core/persistence/DatabaseController.py) provides the main interface for database operations.
Initialization
- Creates the SQLAlchemy engine with the configured connection string
- Creates a session maker
- Creates an active session
- Initializes table controllers for each data type
- Creates all database tables if they don’t exist
- Creates a default admin user on first run
Default Admin User
On first initialization, a default system user is created:Database Tables
FreeTAKServer creates and manages the following database tables:User Tables
- User: TAK client users and their CoT information
- SystemUser: System administrators and API users
- APIUsers: REST API user authentication
Event Tables
- Event: CoT events (when
SaveCoTToDBis enabled) - Archive: Archived CoT data
- Chat: Chat messages
- Emergency: Emergency notifications
- ActiveEmergencys: Currently active emergencies
Data Tables
- DataPackage: Uploaded data packages
- VideoStream: Video stream configurations
- _Video: Video metadata
Checklist Tables
- ExCheck: ExCheck templates
- ExCheckChecklist: ExCheck checklist instances
- ExCheckKeywords: Keywords for ExCheck
- ExCheckData: ExCheck data entries
Federation Tables
- Federations: Federation server configurations
- ActiveFederations: Currently active federation connections
Support Tables
- _Group: CoT group information
- Color: CoT color information
- Contact: Contact details
- Dest: Destination information
- Link: CoT links
- Marti: Marti-specific data
- Precisionlocation: High-precision location data
- Remarks: CoT remarks
- Serverdestination: Server destination routing
- Status: Status information
- Summary: CoT summaries
- Takv: TAK version information
- Track: Tracking data
- Uid: Unique identifiers
- Usericon: User icon data
Logging Tables
- APICalls: REST API access logs
Database Operations
TheDatabaseController provides CRUD operations for all tables.
Create Operations
Query Operations
Update Operations
Delete Operations
Session Management
TheDatabaseController manages SQLAlchemy sessions automatically.
Session Creation
Manual Session Creation
Shutdown Connection
CoT Event Storage
WhenSaveCoTToDB is enabled, all CoT events are stored in the database.
Creating CoT Events
Querying CoT Events
Disabling CoT Storage
To reduce database size and improve performance, you can disable CoT storage:Disabling CoT storage reduces database growth but prevents historical event queries and replay functionality.
Database Migrations
FreeTAKServer uses SQLAlchemy’s metadata system for automatic table creation.Automatic Migration
On startup, the database controller automatically:- Connects to the database
- Checks for the
SystemUsertable - If tables don’t exist, creates all tables from the Base metadata
- Creates default admin user if it’s a new installation
Manual Table Creation
Database Backup
SQLite Backup
MySQL Backup
Performance Optimization
SQLite Optimization
Disable CoT Storage (if not needed):MySQL Optimization
Connection Pooling:Database Troubleshooting
Common Issues
Database locked (SQLite):- Ensure only one FreeTAKServer instance is running
- Check for stuck processes:
lsof /opt/fts/FTSDataBase.db - Enable WAL mode for better concurrency
- Verify MySQL service is running:
systemctl status mysql - Check connection string format
- Verify user permissions:
GRANT ALL ON freetakserver.* TO 'ftsuser'@'localhost'
- Delete database file and restart (SQLite)
- Run manual table creation script
- Check database permissions
- Disable CoT storage if not needed
- Increase
MainLoopDelayto reduce database writes - Use MySQL instead of SQLite for large deployments
Example Configurations
Development (SQLite)
Production (SQLite)
Production (MySQL)
Best Practices
- Regular database backups (automated daily backups recommended)
- Monitor database size and implement retention policies
- Use MySQL for production deployments with many clients
- Disable CoT storage if historical event data is not needed
- Implement database backup automation
- Set appropriate filesystem permissions on database files
- Use connection pooling for MySQL deployments
- Monitor database performance and adjust
MainLoopDelayaccordingly - Keep database files on fast storage (SSD recommended)
- Regularly vacuum SQLite databases to reclaim space