in oracle/pkg/database/dbdaemon/dbdaemon_server.go [622:709]
func (s *Server) createTablespacesFromSqlfile(ctx context.Context, metaFullPath, PDBName string) {
f, err := os.Open(metaFullPath)
if err != nil {
klog.Warningf("Not creating tablespaces for import. Failed to open %q: %v", metaFullPath, err)
return
}
defer func() {
if err := f.Close(); err != nil {
klog.Warningf("failed to close import metafile %v: %v", f, err)
}
}()
// Gather a list of tablespaces required by this sqlfile.
ts := map[string]bool{}
tsTemp := map[string]bool{}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
matches := tsRegexp.FindStringSubmatch(line)
if len(matches) > 0 {
kind := matches[1]
name1 := matches[2]
name2 := matches[3]
if kind == "DEFAULT" || kind == "CREATE" {
ts[name1] = true
}
if kind == "" { // from the grant match.
ts[name2] = true
}
if kind == "TEMPORARY" {
tsTemp[name1] = true
}
}
}
sqlResp, err := s.RunSQLPlusFormatted(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
sqlq.QuerySetSessionContainer(PDBName),
"select contents, tablespace_name from dba_tablespaces",
},
})
if err != nil {
klog.Warningf("createTablespacesFromSqlfile: query tablespaces failed: %v", err)
return
}
// Check what tablespaces already exist and remove them from our list.
tsJSONs := sqlResp.GetMsg()
for _, js := range tsJSONs {
row := make(map[string]string)
if err := json.Unmarshal([]byte(js), &row); err != nil {
klog.Warningf("createTablespacesFromSqlfile: failed to parse pdb tablespaces response: %v", err)
return
}
name := row["TABLESPACE_NAME"]
kind := row["CONTENTS"]
if _, ok := ts[name]; ok && kind == "PERMANENT" {
delete(ts, name)
}
if _, ok := tsTemp[name]; ok && kind == "TEMPORARY" {
delete(tsTemp, name)
}
}
// Create any remaining tablespaces
for t := range ts {
_, err := s.RunSQLPlus(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
sqlq.QuerySetSessionContainer(PDBName),
fmt.Sprintf("create bigfile tablespace \"%s\"", t),
},
})
if err != nil {
klog.Warningf("createTablespacesFromSqlfile: failed to create tablespace %s: %v", t, err)
}
}
for t := range tsTemp {
_, err := s.RunSQLPlus(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
sqlq.QuerySetSessionContainer(PDBName),
fmt.Sprintf("create temporary tablespace \"%s\" size 128M autoextend on", t),
},
})
if err != nil {
klog.Warningf("createTablespacesFromSqlfile: failed to create tablespace %s: %v", t, err)
}
}
}