@@ -20,6 +20,7 @@ import (
2020 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
2121 "github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
2222 "github.com/cockroachdb/cockroach/pkg/upgrade"
23+ "github.com/cockroachdb/cockroach/pkg/util/hlc"
2324 "github.com/cockroachdb/cockroach/pkg/util/log"
2425 "github.com/cockroachdb/cockroach/pkg/util/protoutil"
2526 "github.com/cockroachdb/errors"
@@ -254,6 +255,12 @@ func createDefaultDbs(
254255 // already.
255256 const createDbStmt = `CREATE DATABASE IF NOT EXISTS "%s" WITH OWNER root`
256257
258+ id , _ , _ := readerTenantInfo (ctx , deps )
259+ if id .IsSet () {
260+ // Don't create the default databases for read from standby tenants.
261+ return nil
262+ }
263+
257264 var err error
258265 for _ , dbName := range []string {catalogkeys .DefaultDatabaseName , catalogkeys .PgDatabaseName } {
259266 stmt := fmt .Sprintf (createDbStmt , dbName )
@@ -265,3 +272,21 @@ func createDefaultDbs(
265272 }
266273 return nil
267274}
275+
276+ // readerTenantInfo returns the tenant ID and timestamp if we're spinning up a
277+ // read from standby tenant.
278+ func readerTenantInfo (
279+ ctx context.Context , d upgrade.TenantDeps ,
280+ ) (roachpb.TenantID , hlc.Timestamp , error ) {
281+ if d .TenantInfoAccessor == nil {
282+ return roachpb.TenantID {}, hlc.Timestamp {}, nil
283+ }
284+ id , ts , err := d .TenantInfoAccessor .ReadFromTenantInfo (ctx )
285+ if err != nil {
286+ return roachpb.TenantID {}, hlc.Timestamp {}, err
287+ }
288+ if ! id .IsSet () {
289+ return roachpb.TenantID {}, hlc.Timestamp {}, nil
290+ }
291+ return id , ts , nil
292+ }
0 commit comments