Use when adding, removing, or modifying columns/indexes on system tables. Provides a checklist covering schema definitions, migrations, version gates, golden files, and test hashes.
When adding, removing, or modifying columns or indexes on a system table, multiple files and golden test artifacts must be updated in lockstep. Missing any of these causes test failures that can be confusing to debug.
Update the table's schema string and descriptor literal in:
pkg/sql/catalog/systemschema/system.go
CREATE TABLE schema string (e.g., StatementDiagnosticsRequestsTableSchema)StatementDiagnosticsRequestsTable): columns, column IDs, family column names/IDs, index store column names/IDs, NextColumnIDNextColumnID must be max(column IDs) + 1ColumnNames and ColumnIDs in the family descriptorSTORING clause and the descriptor literal's /StoreColumnNamesStoreColumnIDsIf creating a brand new system table, register it in these additional files:
pkg/sql/sem/catconstants/constants.go
pkg/sql/catalog/catprivilege/system.go
pkg/sql/catalog/bootstrap/metadata.go
pkg/backup/system_schema.go
pkg/cli/zip_table_registry.go
cockroach debug zip output and register it if sopkg/clusterversion/cockroach_versions.go
V26_2_MyChange)versionTable (must use even Internal values, incrementing by 2)pkg/sql/catalog/systemschema/system.go
SystemDatabaseSchemaBootstrapVersion to your new version constantpkg/upgrade/upgrades/
v26_2_my_change.go). For new tables, this uses CREATE TABLE. For existing tables, this uses ALTER TABLE / CREATE INDEX.v26_2_my_change_test.go) with the old descriptor and validationupgrades.goschema_changes.go if needed (existing tables only)helpers_test.go if adding new helper functions./dev gen bazel if adding new filesThese files contain serialized representations of the schema and must be regenerated after schema changes. Update hashes first, then run tests with --rewrite.
pkg/sql/catalog/bootstrap/testdata/testdata
system hash=<sha256> and tenant hash=<sha256> followed by KV data--rewrite to regenerate the KV data./dev test pkg/sql/catalog/bootstrap -f TestInitialValuesToString -v --rewritepkg/sql/catalog/systemschema_test/testdata/bootstrap_systempkg/sql/catalog/systemschema_test/testdata/bootstrap_tenant
./dev test pkg/sql/catalog/systemschema_test -f TestValidateSystemSchemaAfterBootStrap -v --rewritepkg/sql/logictest/testdata/logic_test/pg_catalog — pg_catalog column metadatapkg/sql/logictest/testdata/logic_test/crdb_internal_catalog — internal catalog metadata
./dev testlogic --files=pg_catalog --rewrite./dev testlogic --files=crdb_internal_catalog --rewritepkg/sql/tests/testdata/initial_keys — initial bootstrap keys
./dev test pkg/sql/tests -f TestInitialKeys -v --rewritepkg/sql/catalog/internal/catkv/testdata/testdata_app — catalog cache test data for app tenant
pkg/sql/catalog/internal/catkv/testdata/testdata_system — catalog cache test data for system tenant
./dev test pkg/sql/catalog/internal/catkv -v --rewriteWhen adding a new system table, these additional golden files may need regeneration:
pkg/sql/logictest/testdata/logic_test/information_schema — information_schema metadata
./dev testlogic --files=information_schema --rewritepkg/sql/logictest/testdata/logic_test/system — system table tests
./dev testlogic --files=system --rewritepkg/cli/testdata/doctor/test_examine_cluster* — cluster doctor examination test data
./dev test pkg/cli -f TestDoctor -v --rewritepkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/ — span config reconciler test data
./dev test pkg/ccl/spanconfigccl/spanconfigreconcilerccl -v --rewritepkg/sql/catalog/bootstrap/data/{version}_system.keyspkg/sql/catalog/bootstrap/data/{version}_system.sha256pkg/sql/catalog/bootstrap/data/{version}_tenant.keyspkg/sql/catalog/bootstrap/data/{version}_tenant.sha256
LatestAdding a version constant changes the version cluster setting's default value, which is reflected in generated settings docs. Regenerate with:
./dev gen docs
If the schema change adds a column/index used at runtime, gate usage on the version:
if settings.Version.IsActive(ctx, clusterversion.V26_2_MyChange) {
// Use the new column/index
}
This ensures mixed-version clusters work during rolling upgrades.
Re-run the tests from Section 5 without --rewrite to confirm everything passes. Also run your migration test:
./dev test pkg/upgrade/upgrades -f TestMyMigration -v
Golden files frequently conflict during rebases because multiple PRs change system tables concurrently. The resolution pattern:
--rewritebootstrap/testdata/testdata (run test, grep "Unexpected hash", update, re-run with --rewrite)Never try to manually merge golden file content — always regenerate.