bytebase/bytebase · error

database owner is required for CockroachDB

Error message

database owner is required for CockroachDB

What it means

Returned by checkCharacterSetCollationOwner when a create-database config targets a CockroachDB instance but the owner field is empty. Like PostgreSQL (which CockroachDB is wire-compatible with), CREATE DATABASE there expects an owner role, so Bytebase requires owner for this engine before generating the task.

Source

Thrown at backend/api/v1/rollout_service_task.go:385

		}
	case storepb.Engine_SNOWFLAKE:
		if characterSet != "" {
			return errors.Errorf("Snowflake does not support character set, but got %s", characterSet)
		}
		if collation != "" {
			return errors.Errorf("Snowflake does not support collation, but got %s", collation)
		}
	case storepb.Engine_POSTGRES:
		if owner == "" {
			return errors.Errorf("database owner is required for PostgreSQL")
		}
	case storepb.Engine_REDSHIFT:
		if owner == "" {
			return errors.Errorf("database owner is required for Redshift")
		}
	case storepb.Engine_COCKROACHDB:
		if owner == "" {
			return errors.Errorf("database owner is required for CockroachDB")
		}
	case storepb.Engine_MONGODB, storepb.Engine_MSSQL, storepb.Engine_DORIS, storepb.Engine_STARROCKS:
		// no-op.
	default:
		if characterSet == "" {
			return errors.Errorf("character set missing for %s", dbType.String())
		}
		// For postgres, we don't explicitly specify a default since the default might be UNSET (denoted by "C").
		// If that's the case, setting an explicit default such as "en_US.UTF-8" might fail if the instance doesn't
		// install it.
		if collation == "" {
			return errors.Errorf("collation missing for %s", dbType.String())
		}
	}
	return nil
}

func getCreateDatabaseStatement(dbType storepb.Engine, c *storepb.PlanConfig_CreateDatabaseConfig, databaseName, adminDatasourceUser string) (string, error) {

View on GitHub (pinned to 1870550677)

Solutions

  1. Set createDatabaseConfig.owner to a valid CockroachDB user/role.
  2. Verify the role exists (SHOW USERS) on the target cluster before rollout.
  3. Ensure plan templates always include owner for the Postgres-family engines (Postgres, Redshift, CockroachDB).

Example fix

// before
{"database": "app", "owner": ""}
// after
{"database": "app", "owner": "crdb_admin"}
Defensive patterns

Strategy: validation

Validate before calling

if engine == storepb.Engine_COCKROACHDB && cfg.GetCreateDatabaseConfig().GetOwner() == "" {
    return fmt.Errorf("owner is required when creating database %q on CockroachDB", cfg.GetCreateDatabaseConfig().GetDatabase())
}

Type guard

func cockroachCreateConfigValid(cfg *storepb.PlanConfig_CreateDatabaseConfig) bool {
    return cfg != nil && strings.TrimSpace(cfg.GetOwner()) != ""
}

Prevention

When it happens

Trigger: Plan targeting CockroachDB with createDatabaseConfig.owner == "" at rollout task creation time in the rollout service.

Common situations: Plans authored for Postgres then switched to CockroachDB where owner got dropped; automation constructing configs without the owner field; renamed or removed CockroachDB user.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/01a3c748dd3ae221. Report an issue: GitHub.