3.1 KiB
SQLite Installation and Troubleshooting
Overview
TrafegoDNS uses SQLite as its primary database storage. This document explains how the SQLite integration works and how to troubleshoot common issues.
Requirements
For SQLite to work properly, the application requires:
- The
better-sqlite3Node.js package - SQLite system libraries (
sqliteandsqlite-devin Alpine Linux) - Python with setuptools (for building native modules)
- C/C++ compilation tools (make, g++)
- Proper database directory permissions
Common Issues
Common Errors
Missing Package Error
If you see this error in the logs, it means the better-sqlite3 package is not installed:
Could not import better-sqlite3: Cannot find package 'better-sqlite3' imported from /app/src/database/sqlite-core.js
This occurs when:
- The package was not installed during the container build
- The package is listed as an optional dependency but was not installed
Native Module Build Failure
If you see errors related to node-gyp or Python's distutils module:
ModuleNotFoundError: No module named 'distutils'
This means the build environment lacks the necessary tools to compile the native SQLite module. Ensure you have:
- Python 3 with pip installed
- Python setuptools (py3-setuptools in Alpine Linux)
- C/C++ build tools (make, g++, etc.)
- SQLite development libraries (sqlite-dev in Alpine Linux)
Restart Loop
If TrafegoDNS is stuck in a restart loop with SQLite errors, the issue is likely related to one of the following:
- Missing
better-sqlite3package - Database directory permission issues
- Corrupted database file
Fixed Implementation
The latest Docker image includes these improvements:
better-sqlite3is now a required dependency inpackage.json- The Dockerfile explicitly installs
better-sqlite3during the build - The container initialization script runs a SQLite fix script to ensure proper setup
Manual Fix for Existing Installations
If you're experiencing SQLite issues with an existing installation:
-
Run the fix script inside the container:
docker exec -it trafegodns /app/docker-s6/scripts/fix-sqlite.sh -
Restart the container after the fix:
docker restart trafegodns
Database Directory Permissions
TrafegoDNS stores its SQLite database at /config/data/trafegodns.db. Ensure this directory:
- Is mounted as a persistent volume
- Has the proper ownership (uid 1001, gid 1001 for the
abcuser) - Has write permissions (755 for directory, 644 for database file)
Complete Reset
If your database is corrupted or you want to start fresh:
-
Run the reset script:
docker exec -it trafegodns /app/docker-s6/scripts/reset-sqlite.shWarning: This will delete all database records!
-
Restart the container:
docker restart trafegodns
Built-in Database Maintenance
The application now includes automatic database maintenance features:
- Automatic WAL journal mode configuration
- Transaction handling improvements
- File-based locking to prevent concurrent access issues
- Automatic stale lock detection and cleanup