{"record":{"id":"bff21ef69241074d","repo":"henrygd/beszel","slug":"failed-to-delete-old-systemd-service-records-v","errorCode":null,"errorMessage":"failed to delete old systemd service records: %v","messagePattern":"failed to delete old systemd service records: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/records/records_deletion.go","lineNumber":110,"sourceCode":"\t\tconditionStr := strings.Join(conditionParts, \" OR \")\n\t\t// Construct and execute the full raw query\n\t\trawQuery := fmt.Sprintf(\"DELETE FROM %s WHERE %s\", collection, conditionStr)\n\t\tif _, err := app.DB().NewQuery(rawQuery).Bind(params).Execute(); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to delete from %s: %v\", collection, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// Deletes systemd service records that haven't been updated in the last 20 minutes\nfunc deleteOldSystemdServiceRecords(app core.App) error {\n\tnow := time.Now().UTC()\n\ttwentyMinutesAgo := now.Add(-20 * time.Minute)\n\n\t// Delete systemd service records where updated < twentyMinutesAgo\n\t_, err := app.DB().NewQuery(\"DELETE FROM systemd_services WHERE updated < {:updated}\").Bind(dbx.Params{\"updated\": twentyMinutesAgo.UnixMilli()}).Execute()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to delete old systemd service records: %v\", err)\n\t}\n\n\treturn nil\n}\n\n// Deletes container records that haven't been updated in the last 10 minutes\nfunc deleteOldContainerRecords(app core.App) error {\n\tnow := time.Now().UTC()\n\ttenMinutesAgo := now.Add(-10 * time.Minute)\n\n\t// Delete container records where updated < tenMinutesAgo\n\t_, err := app.DB().NewQuery(\"DELETE FROM containers WHERE updated < {:updated}\").Bind(dbx.Params{\"updated\": tenMinutesAgo.UnixMilli()}).Execute()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to delete old container records: %v\", err)\n\t}\n\n\treturn nil\n}","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/records/records_deletion.go#L92-L128","documentation":"deleteOldSystemdServiceRecords runs a DELETE on the systemd_services collection for rows not updated in the last 20 minutes. A failed query execution is wrapped in this error, identifying the systemd retention cleanup as the failing step.","triggerScenarios":"The DELETE FROM systemd_services query fails: database locked, disk full, or the systemd_services collection missing/renamed in the schema.","commonSituations":"SQLite lock contention during cleanup cron; upgraded instances where the systemd_services collection was renamed; disk exhaustion on the hub host.","solutions":["Inspect the wrapped error for the SQLite root cause (locked/disk full/no such table)","Confirm the systemd_services collection exists in the current PocketBase schema","Check disk space and DB lock contention around the cleanup schedule"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if !collectionExists(app, \"systemd_services\") {\n    return errors.New(\"systemd_services collection missing\")\n}","typeGuard":null,"tryCatchPattern":"if err := deleteOldSystemdServiceRecords(app); err != nil {\n    log.Error().Err(err).Msg(\"systemd service retention cleanup failed\")\n    // check for SQLite lock/disk errors and retry later\n}","preventionTips":["Confirm systemd_services collection exists after upgrades","Schedule cleanup away from backup jobs holding DB locks","Monitor disk usage and DB error logs"],"tags":["database","sqlite","retention","systemd"],"backgroundTag":"database-delete-failed","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}