Files
claudetools/check-db-performance.ps1
Mike Swanson e4392afce9 docs: Document Dataforth test database system and troubleshooting
Investigation and Documentation:
- Discovered and documented test database system on AD2 server
- Created comprehensive TEST_DATABASE_ARCHITECTURE.md with full system details
- Retrieved all key database files from AD2 (import.js, schema.sql, server configs)
- Documented data flow: DOS machines → NAS → AD2 → SQLite → Web interface
- Verified database health: 1,027,517 records, 1075 MB, dates back to 1990

Database System Architecture:
- SQLite database with Node.js/Express.js web server (port 3000)
- Automated import via Sync-FromNAS.ps1 (runs every 15 minutes)
- 8 log types supported: DSCLOG, 5BLOG, 7BLOG, 8BLOG, PWRLOG, SCTLOG, VASLOG, SHT
- FTS5 full-text search, comprehensive indexes for performance
- API endpoints: search, stats, export, datasheet generation

Troubleshooting Scripts Created:
- Database diagnostics: check-db-simple.ps1, test-db-directly.ps1
- Server status checks: check-node-running.ps1, check-db-server.ps1
- Performance analysis: check-db-performance.ps1, check-wal-files.ps1
- API testing: test-api-endpoint.ps1, test-query.js
- Import monitoring: check-new-records.ps1
- Database optimization attempts: api-js-optimized.js, api-js-fixed.js
- Deployment scripts: deploy-db-optimization.ps1, deploy-db-fix.ps1, restore-original.ps1

Key Findings:
- Database file healthy and queryable (verified with test-query.js)
- Node.js server not running (port 3000 closed) - root cause of web interface issues
- Database last updated 8 days ago (01/13/2026) - automated sync may be broken
- Attempted performance optimizations (WAL mode) incompatible with readonly connections
- Original api.js restored from backup after optimization conflicts

Retrieved Documentation:
- QUICKSTART-retrieved.md: Quick start guide for database server
- SESSION_NOTES-retrieved.md: Complete session notes from database creation
- Sync-FromNAS-retrieved.ps1: Full sync script with database import logic
- import-js-retrieved.js: Node.js import script (12,774 bytes)
- schema-retrieved.sql: SQLite schema with FTS5 triggers
- server-js-retrieved.js: Express.js server configuration
- api-js-retrieved.js: API routes and endpoints
- package-retrieved.json: Node.js dependencies

Action Items Identified:
1. Start Node.js server on AD2 to restore web interface functionality
2. Investigate why automated sync hasn't updated database in 8 days
3. Check Windows Task Scheduler for Sync-FromNAS.ps1 scheduled task
4. Run manual import to catch up on 8 days of test data if needed

Technical Details:
- Database path: C:\Shares\testdatadb\database\testdata.db
- Web interface: http://192.168.0.6:3000 (when running)
- Database size: 1075.14 MB (1,127,362,560 bytes)
- Total records: 1,027,517 (slight variance from original 1,030,940)
- Pass rate: 99.82% (1,029,046 passed, 1,888 failed)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-21 16:38:54 -07:00

70 lines
3.2 KiB
PowerShell

# Check database performance and optimization status
$password = ConvertTo-SecureString 'Paper123!@#' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('INTRANET\sysadmin', $password)
Write-Host "[OK] Mounting AD2 C$ share..." -ForegroundColor Green
New-PSDrive -Name AD2 -PSProvider FileSystem -Root "\\192.168.0.6\C$" -Credential $cred -ErrorAction Stop | Out-Null
# Get server.js content to check timeout settings
Write-Host "[OK] Checking server.js configuration..." -ForegroundColor Green
$serverJs = Get-Content "AD2:\Shares\testdatadb\server.js" -Raw
if ($serverJs -match "timeout") {
Write-Host "[FOUND] Timeout configuration in server.js" -ForegroundColor Yellow
$serverJs -split "`n" | Where-Object { $_ -match "timeout" } | ForEach-Object {
Write-Host " $_" -ForegroundColor Cyan
}
} else {
Write-Host "[INFO] No explicit timeout configuration found" -ForegroundColor Cyan
}
# Check if better-sqlite3 is configured for performance
if ($serverJs -match "pragma") {
Write-Host "[FOUND] SQLite PRAGMA settings:" -ForegroundColor Green
$serverJs -split "`n" | Where-Object { $_ -match "pragma" } | ForEach-Object {
Write-Host " $_" -ForegroundColor Cyan
}
} else {
Write-Host "[WARNING] No PRAGMA performance settings found in server.js" -ForegroundColor Yellow
Write-Host " Consider adding: PRAGMA journal_mode = WAL, PRAGMA synchronous = NORMAL" -ForegroundColor Yellow
}
# Check routes/api.js for query optimization
Write-Host "`n[OK] Checking API routes..." -ForegroundColor Green
if (Test-Path "AD2:\Shares\testdatadb\routes\api.js") {
$apiJs = Get-Content "AD2:\Shares\testdatadb\routes\api.js" -Raw
# Check for LIMIT clauses
$hasLimit = $apiJs -match "LIMIT"
if ($hasLimit) {
Write-Host "[OK] Found LIMIT clauses in queries (good for performance)" -ForegroundColor Green
} else {
Write-Host "[WARNING] No LIMIT clauses found - queries may return too many results" -ForegroundColor Yellow
}
# Check for index usage
$hasIndexHints = $apiJs -match "INDEXED BY" -or $apiJs -match "USE INDEX"
if ($hasIndexHints) {
Write-Host "[OK] Found index hints in queries" -ForegroundColor Green
} else {
Write-Host "[INFO] No explicit index hints (relying on automatic optimization)" -ForegroundColor Cyan
}
}
# Check database file fragmentation
Write-Host "`n[OK] Checking database file stats..." -ForegroundColor Green
$dbFile = Get-Item "AD2:\Shares\testdatadb\database\testdata.db"
Write-Host " File size: $([math]::Round($dbFile.Length/1MB,2)) MB" -ForegroundColor Cyan
Write-Host " Last accessed: $($dbFile.LastAccessTime)" -ForegroundColor Cyan
Write-Host " Last modified: $($dbFile.LastWriteTime)" -ForegroundColor Cyan
# Suggestion to run VACUUM
$daysSinceModified = (Get-Date) - $dbFile.LastWriteTime
if ($daysSinceModified.TotalDays -gt 7) {
Write-Host "`n[SUGGESTION] Database hasn't been modified in $([math]::Round($daysSinceModified.TotalDays,1)) days" -ForegroundColor Yellow
Write-Host " Consider running VACUUM to optimize database file" -ForegroundColor Yellow
}
Remove-PSDrive -Name AD2 -ErrorAction SilentlyContinue
Write-Host "`n[OK] Done" -ForegroundColor Green