in oracle/pkg/agents/standby/promote_standby_task.go [67:133]
func (task *promoteStandbyTask) promoteStandby(ctx context.Context) error {
// Prepare promotion by cancelling managed recovery processes for standby.
klog.InfoS("checking current managed recovery processes")
res, err := fetchAndParseQueries(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{consts.ListMRPSql},
ConnectInfo: &dbdpb.RunSQLPlusCMDRequest_Local{},
}, task.dbdClient)
if err != nil {
// Log the non-critical error and continue.
klog.ErrorS(err, "error while querying managed recovery processes")
}
if len(res) > 0 {
klog.InfoS("found managed recovery processes", "res", res)
klog.InfoS("cancelling managed recovery processes for standby")
if _, err = task.dbdClient.RunSQLPlus(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
consts.CancelMRPSql,
},
}); err != nil {
// Log the non-critical error and continue.
klog.ErrorS(err, "error while cancelling managed recovery processes")
}
}
// Promote standby database to primary.
klog.InfoS("checking standby database role")
res, err = fetchAndParseQueries(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{consts.ListPrimaryRoleSql},
ConnectInfo: &dbdpb.RunSQLPlusCMDRequest_Local{},
}, task.dbdClient)
if err != nil {
// Log the non-critical error and continue.
klog.ErrorS(err, "error while checking standby database role")
}
if len(res) < 1 {
klog.InfoS("promoting standby database to primary")
if _, err = task.dbdClient.RunSQLPlus(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
consts.ActivateStandbySql,
},
}); err != nil {
return fmt.Errorf("promoteStandby: Error while promoting standby database: %v", err)
}
}
// Open new primary database.
klog.InfoS("checking if new primary database is open")
res, err = fetchAndParseQueries(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{consts.ListOpenDatabaseSql},
ConnectInfo: &dbdpb.RunSQLPlusCMDRequest_Local{},
}, task.dbdClient)
if err != nil {
// Log the non-critical error and continue.
klog.ErrorS(err, "error while checking new primary database status")
}
if len(res) < 1 {
klog.InfoS("opening new primary database")
if _, err = task.dbdClient.RunSQLPlus(ctx, &dbdpb.RunSQLPlusCMDRequest{
Commands: []string{
consts.OpenDatabaseSql,
},
}); err != nil {
return fmt.Errorf("promoteStandby: Error while opening new primary database: %v", err)
}
}
return nil
}