fix(oracle): check via v$instance
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Markus Pesch 2021-09-22 11:08:38 +02:00
parent 081f147657
commit 760c55f48e
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"os"
"strings"
"time"
)
@ -44,16 +45,35 @@ LOOP:
switch databaseURL.Scheme {
case "oracle":
_, err := sqlDB.QueryContext(queryCtx, "SELECT 1 FROM dual")
row := sqlDB.QueryRowContext(queryCtx, "SELECT INSTANCE_NAME, STATUS, DATABASE_STATUS FROM V$INSTANCE WHERE INSTANCE_NAME=$1", databaseURL.Path)
var instaceName string
var instanceStatus string
var databaseStatus string
err := row.Scan(instaceName, instanceStatus, databaseStatus)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", time.Now().String(), err.Error())
ticker.Reset(period)
continue LOOP
}
if strings.ToUpper(instanceStatus) != "OPEN" {
fmt.Fprintf(os.Stderr, "%s: Instance status is not open: %s\n", time.Now().String(), instanceStatus)
ticker.Reset(period)
continue LOOP
}
if strings.ToUpper(databaseStatus) != "OPEN" {
fmt.Fprintf(os.Stderr, "%s: Database status is not active: %s\n", time.Now().String(), databaseStatus)
ticker.Reset(period)
continue LOOP
}
return nil
case "postgres":
_, err := sqlDB.QueryContext(queryCtx, "SELECT 1 AS ROW")
if err != nil {
row := sqlDB.QueryRowContext(queryCtx, "SELECT 1 AS ROW")
if row.Err() != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", time.Now().String(), err.Error())
ticker.Reset(period)
continue LOOP