{"record":{"id":"47c161cb26c8f062","repo":"SigNoz/signoz","slug":"error-in-processing-ttl-status-check-sql-query","errorCode":null,"errorMessage":"error in processing ttl_status check sql query","messagePattern":"error in processing ttl_status check sql query","errorType":"exception","errorClass":"model.ApiError","httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":955,"sourceCode":"\tuuid := strings.Replace(uuidWithHyphen.String(), \"-\", \"\", -1)\n\n\tcoldStorageDuration := -1\n\tif len(params.ColdStorageVolume) > 0 {\n\t\tcoldStorageDuration = int(params.ToColdStorageDuration)\n\t}\n\n\ttableNameArray := []string{\n\t\tr.logsDB + \".\" + r.logsLocalTableV2,\n\t\tr.logsDB + \".\" + r.logsResourceLocalTableV2,\n\t\tgetLocalTableName(r.logsDB + \".\" + r.logsAttributeKeys),\n\t\tgetLocalTableName(r.logsDB + \".\" + r.logsResourceKeys),\n\t}\n\n\t// check if there is existing things to be done\n\tfor _, tableName := range tableNameArray {\n\t\tstatusItem, apiErr := r.checkTTLStatusItem(ctx, orgID, tableName)\n\t\tif apiErr != nil {\n\t\t\treturn nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf(\"error in processing ttl_status check sql query\")}\n\t\t}\n\t\tif statusItem.Status == retentiontypes.TTLSettingStatusPending {\n\t\t\treturn nil, &model.ApiError{Typ: model.ErrorConflict, Err: fmt.Errorf(\"TTL is already running\")}\n\t\t}\n\t}\n\n\t// TTL query for logs_v2 table\n\tttlLogsV2 := fmt.Sprintf(\n\t\t\"ALTER TABLE %v ON CLUSTER %s MODIFY TTL toDateTime(timestamp / 1000000000) + \"+\n\t\t\t\"INTERVAL %v SECOND DELETE\", tableNameArray[0], r.cluster, params.DelDuration)\n\tif len(params.ColdStorageVolume) > 0 {\n\t\tttlLogsV2 += fmt.Sprintf(\", toDateTime(timestamp / 1000000000)\"+\n\t\t\t\" + INTERVAL %v SECOND TO VOLUME '%s'\",\n\t\t\tparams.ToColdStorageDuration, params.ColdStorageVolume)\n\t}\n\n\t// TTL query for logs_v2_resource table\n\t// adding 1800 as our bucket size is 1800 seconds","sourceCodeStart":937,"sourceCodeEnd":973,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L937-L973","documentation":"ApiError (ErrorExec) from setTTLLogs when checkTTLStatusItem fails for any table in the TTL set — the query that reads the current ttl_status (pending/running state) errors out, so a new TTL change cannot be gated safely. Distinct from the adjacent 'TTL is already running' (ErrorConflict) which fires when status is legitimately pending.","triggerScenarios":"Initiating a logs TTL change while the ttl_status lookup query fails: missing/corrupt ttl_status table, CH connection errors, or permission problems on the metadata table.","commonSituations":"Deployments where TTL metadata migrations didn't run, CH user lacking access to the TTL status table, or transient CH failures during retention updates.","solutions":["Inspect logs for why checkTTLStatusItem failed","Verify the ttl_status table exists (run migrations) and is readable by the CH user","Fix ClickHouse connectivity/permissions and retry the TTL update"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if !tableExists(ctx, ch, metaDB, ttlStatusTable) {\n    return fmt.Errorf(\"ttl_status table missing; run migrations\")\n}","typeGuard":"func isTtlStatusErr(apiErr *model.ApiError) bool {\n    return apiErr != nil && apiErr.Typ == model.ErrorExec && strings.Contains(apiErr.Err.Error(), \"ttl_status check sql query\")\n}","tryCatchPattern":"_, apiErr := reader.SetTTL(ctx, orgID, params)\nif isTtlStatusErr(apiErr) {\n    logMigrationsNeeded()\n    return apiErr // fix schema, don't retry\n} else if apiErr != nil && strings.Contains(apiErr.Err.Error(), \"already running\") {\n    // wait for pending TTL, then re-queue\n}","preventionTips":["Run TTL metadata migrations with the app upgrade","Distinguish status-read errors from genuine pending-TTL conflicts","Expose TTL status in dashboards to avoid blind change attempts"],"tags":["ttl","retention","clickhouse","metadata"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}