diff --git a/pkg/sql/alter_database.go b/pkg/sql/alter_database.go index 04a5a11d2eac..1a61cc5e8309 100644 --- a/pkg/sql/alter_database.go +++ b/pkg/sql/alter_database.go @@ -15,6 +15,7 @@ import ( "fmt" "sort" + "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/security" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv" @@ -423,6 +424,15 @@ func (n *alterDatabasePrimaryRegionNode) startExec(params runParams) error { return err } + // Block adding a primary region to the system database. This ensures that the system + // database can never be made into a multi-region database. + if n.desc.GetID() == keys.SystemDatabaseID { + return pgerror.Newf( + pgcode.FeatureNotSupported, + "adding a primary region to the system database is not supported", + ) + } + // There are two paths to consider here: either this is the first setting of the // primary region, OR we're updating the primary region. In the case where this // is the first setting of the primary region, the call will turn the database into diff --git a/pkg/sql/logictest/testdata/logic_test/multiregion b/pkg/sql/logictest/testdata/logic_test/multiregion index 44740e7b06c3..7d1ec3094590 100644 --- a/pkg/sql/logictest/testdata/logic_test/multiregion +++ b/pkg/sql/logictest/testdata/logic_test/multiregion @@ -330,6 +330,10 @@ USE new_db statement error database new_db is not multi-region enabled, but table cannot_create_table_no_multiregion has locality GLOBAL set CREATE TABLE cannot_create_table_no_multiregion (a int) LOCALITY GLOBAL +# Test adding a primary region to the system database. +statement error adding a primary region to the system database is not supported +ALTER DATABASE system PRIMARY REGION "ap-southeast-2" + statement ok CREATE DATABASE alter_test_db primary region "ca-central-1"