{"record":{"id":"0e3066a40aa995de","repo":"SigNoz/signoz","slug":"error-while-getting-ttl-err-v","errorCode":null,"errorMessage":"error while getting ttl. Err=%v","messagePattern":"error while getting ttl\\. Err=(.+?)","errorType":"exception","errorClass":"model.ApiError","httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":2084,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn -1, -1\n\t\t\t}\n\t\t\tmoveTTL = seconds_int / 3600\n\t\t}\n\n\t\treturn delTTL, moveTTL\n\t}\n\n\tgetMetricsTTL := func() (*retentiontypes.DBResponseTTL, *model.ApiError) {\n\t\tvar dbResp []retentiontypes.DBResponseTTL\n\n\t\tquery := fmt.Sprintf(\"SELECT engine_full FROM system.tables WHERE name='%v'\", signozSampleLocalTableName)\n\n\t\terr := r.db.Select(ctx, &dbResp, query)\n\n\t\tif err != nil {\n\t\t\tr.logger.Error(\"error while getting ttl\", errorsV2.Attr(err))\n\t\t\treturn nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf(\"error while getting ttl. Err=%v\", err)}\n\t\t}\n\t\tif len(dbResp) == 0 {\n\t\t\treturn nil, nil\n\t\t} else {\n\t\t\treturn &dbResp[0], nil\n\t\t}\n\t}\n\n\tgetTracesTTL := func() (*retentiontypes.DBResponseTTL, *model.ApiError) {\n\t\tvar dbResp []retentiontypes.DBResponseTTL\n\n\t\tquery := fmt.Sprintf(\"SELECT engine_full FROM system.tables WHERE name='%v' AND database='%v'\", r.traceLocalTableName, signozTraceDBName)\n\n\t\terr := r.db.Select(ctx, &dbResp, query)\n\n\t\tif err != nil {\n\t\t\tr.logger.Error(\"error while getting ttl\", errorsV2.Attr(err))\n\t\t\treturn nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf(\"error while getting ttl. Err=%v\", err)}","sourceCodeStart":2066,"sourceCodeEnd":2102,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L2066-L2102","documentation":"Thrown by SigNoz ClickHouseReader when the SELECT of engine_full from system.tables for the metrics/distributed sample table fails. It wraps the underlying sql/database error with model.ErrorExec. The engine_full value is used to parse TTL (retention) settings of the table.","triggerScenarios":"Calling GetTTL (or the retention/TTL API endpoint) for type=metrics when ClickHouse is unreachable, the signoz_sample_local/distributed table does not exist, or the connected user lacks SELECT privileges on system.tables.","commonSituations":"Fresh install where the metrics schema/migrations have not been created yet, wrong CLICKHOUSE_DB or cluster configuration pointing at an empty database, ClickHouse restarted or network partitioned, or upgraded SigNoz version where table names changed.","solutions":["Verify ClickHouse connectivity and that the table exists: SELECT engine_full FROM system.tables WHERE name='signoz_sample_local' (or the configured name) in the configured database","Check the reader configuration (db name, table name, DSN) in your SigNoz settings matches the actual ClickHouse deployment","Run SigNoz schema migrations / the setup that creates the metrics tables if they are missing","Grant the ClickHouse user SELECT access to system.tables if permission is denied","Inspect the wrapped err in the log line 'error while getting ttl' for the true cause (auth failure, unknown table, timeout)"],"exampleFix":"-- before: table missing\nSELECT engine_full FROM system.tables WHERE name='signoz_sample_local'; -- 0 rows / error\n-- after: create the table (or run migrations) then retry\nCREATE TABLE IF NOT EXISTS signoz_metrics.distributed_signoz_sample_local ... ;\n-- then GET /api/v1/retention?type=metrics returns TTL","handlingStrategy":"validation","validationCode":"// before calling GetTTL for metrics, verify the table exists\nvar n uint8\nerr := ch.QueryRow(ctx, \"SELECT count() FROM system.tables WHERE database=? AND name=?\", dbName, signozSampleLocalTableName).Scan(&n)\nif err != nil || n == 0 { return fmt.Errorf(\"metrics table missing; run migrations: %v\", err) }","typeGuard":"func hasMetricsTable(n uint8) bool { return n > 0 }","tryCatchPattern":"if apiErr, ok := err.(*model.ApiError); ok && apiErr.Typ == model.ErrorExec { /* log apiErr.Err, surface 503, check ClickHouse health */ }","preventionTips":["Run schema migrations before starting query-service","Health-check ClickHouse connectivity at startup","Keep table-name config in sync with the deployed schema"],"tags":["clickhouse","signoz","ttl","retention","database-query"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}