SigNoz/signoz · error · model.ApiError

error while getting ttl. Err=%v

Error message

error while getting ttl. Err=%v

What it means

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.

Source

Thrown at pkg/query-service/app/clickhouseReader/reader.go:2084

			if err != nil {
				return -1, -1
			}
			moveTTL = seconds_int / 3600
		}

		return delTTL, moveTTL
	}

	getMetricsTTL := func() (*retentiontypes.DBResponseTTL, *model.ApiError) {
		var dbResp []retentiontypes.DBResponseTTL

		query := fmt.Sprintf("SELECT engine_full FROM system.tables WHERE name='%v'", signozSampleLocalTableName)

		err := r.db.Select(ctx, &dbResp, query)

		if err != nil {
			r.logger.Error("error while getting ttl", errorsV2.Attr(err))
			return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("error while getting ttl. Err=%v", err)}
		}
		if len(dbResp) == 0 {
			return nil, nil
		} else {
			return &dbResp[0], nil
		}
	}

	getTracesTTL := func() (*retentiontypes.DBResponseTTL, *model.ApiError) {
		var dbResp []retentiontypes.DBResponseTTL

		query := fmt.Sprintf("SELECT engine_full FROM system.tables WHERE name='%v' AND database='%v'", r.traceLocalTableName, signozTraceDBName)

		err := r.db.Select(ctx, &dbResp, query)

		if err != nil {
			r.logger.Error("error while getting ttl", errorsV2.Attr(err))
			return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("error while getting ttl. Err=%v", err)}

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. 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
  2. Check the reader configuration (db name, table name, DSN) in your SigNoz settings matches the actual ClickHouse deployment
  3. Run SigNoz schema migrations / the setup that creates the metrics tables if they are missing
  4. Grant the ClickHouse user SELECT access to system.tables if permission is denied
  5. Inspect the wrapped err in the log line 'error while getting ttl' for the true cause (auth failure, unknown table, timeout)

Example fix

-- before: table missing
SELECT engine_full FROM system.tables WHERE name='signoz_sample_local'; -- 0 rows / error
-- after: create the table (or run migrations) then retry
CREATE TABLE IF NOT EXISTS signoz_metrics.distributed_signoz_sample_local ... ;
-- then GET /api/v1/retention?type=metrics returns TTL
Defensive patterns

Strategy: validation

Validate before calling

// before calling GetTTL for metrics, verify the table exists
var n uint8
err := ch.QueryRow(ctx, "SELECT count() FROM system.tables WHERE database=? AND name=?", dbName, signozSampleLocalTableName).Scan(&n)
if err != nil || n == 0 { return fmt.Errorf("metrics table missing; run migrations: %v", err) }

Type guard

func hasMetricsTable(n uint8) bool { return n > 0 }

Try / catch

if apiErr, ok := err.(*model.ApiError); ok && apiErr.Typ == model.ErrorExec { /* log apiErr.Err, surface 503, check ClickHouse health */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/0e3066a40aa995de. Report an issue: GitHub.