in oracle/pkg/agents/standby/set_up_data_guard_task.go [100:167]
func (task *setUpDataGuardTask) ensureStandbyLog(ctx context.Context) error {
res, err := fetchAndParseQueries(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{"select group# from v$standby_log"},
Suppress: true,
ConnectInfo: &dbdpb.RunSQLPlusCMDRequest_Local{},
}, task.dbdClient)
if err != nil {
klog.ErrorS(err, "error while reading standby log information")
// not critical, continue
return nil
}
if len(res) > 0 {
klog.InfoS("found standby logs", "res", res)
return nil
}
klog.InfoS("adding standby logs for standby")
passwd, err := task.primary.PasswordAccessor.Get(ctx)
if err != nil {
klog.ErrorS(err, "error while accessing secret")
// not critical, continue
return nil
}
res, err = fetchAndParseQueries(
ctx,
&dbdpb.RunSQLPlusCMDRequest{
Commands: []string{"select bytes/1024/1024 from v$log"},
Suppress: true,
ConnectInfo: &dbdpb.RunSQLPlusCMDRequest_Dsn{
Dsn: connect.EZ(task.primary.User, passwd, task.primary.Host, strconv.Itoa(task.primary.Port), task.primary.Service, true),
},
},
task.dbdClient)
if err != nil {
klog.ErrorS(err, "error while reading primary log information")
// not critical, continue
return nil
}
if len(res) == 0 {
klog.Warningf("got primary log bytes %v, skip adding standby log", err)
return nil
}
for _, byteKV := range res {
byteVal, ok := byteKV["BYTES/1024/1024"]
if !ok {
klog.Errorf("error while parsing primary log information: %v", byteKV)
// not critical, continue
return nil
}
if _, err = task.dbdClient.RunSQLPlus(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
fmt.Sprintf("alter database add standby logfile thread 1 size %sM", byteVal),
},
}); err != nil {
klog.ErrorS(err, "error while adding standby log")
return nil
}
}
if _, err = task.dbdClient.RunSQLPlus(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
fmt.Sprintf("alter database add standby logfile thread 1 size %sM", res[0]["BYTES/1024/1024"]),
},
}); err != nil {
klog.ErrorS(err, "error while adding standby log")
return nil
}
return nil
}