func (p Postgres) CheckStatus() error {
	db, err := p.getDbConn(p.Database, p.User, p.Password)
	if err != nil {
		return fmt.Errorf("db conn test failed - couldn't get db conn: %s", err)
	}
	defer db.Close()
	_, err = db.Query("SELECT 1")
	if err != nil {
		return fmt.Errorf("db conn test failed - failed to execute query: %s", err)
	}
	err = p.checkExtensions()
	if err != nil {
		return err
	}
	return nil
}
CheckStatus checks status of postgres database
if the connection to database works
package database
import (
	"database/sql"
	"errors"
	"fmt"
	"time"
	_ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres"
	"github.com/kloeckner-i/db-operator/pkg/utils/kci"
	"github.com/lib/pq"
	"github.com/sirupsen/logrus"
)
type Postgres struct {
	Backend      string
	Host         string
	Port         uint16
	Database     string
	User         string
	Password     string
	Extensions   []string
	SSLEnabled   bool
	SkipCAVerify bool
}
const postgresDefaultSSLMode = "disable"
func (p Postgres) sslMode() string {
	if !p.SSLEnabled {
		return "disable"
	}
	if p.SSLEnabled && !p.SkipCAVerify {
		return "verify-ca"
	}
	if p.SSLEnabled && p.SkipCAVerify {
		return "require"
	}
	return postgresDefaultSSLMode
}
func (p Postgres) getDbConn(dbname, user, password string) (*sql.DB, error) {
	var db *sql.DB
	var sqldriver string
	switch p.Backend {
	case "google":
		sqldriver = "cloudsqlpostgres"
	default:
		sqldriver = "postgres"
	}
	dataSourceName := fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s sslmode=%s", p.Host, p.Port, dbname, user, password, p.sslMode())
	db, err := sql.Open(sqldriver, dataSourceName)
	if err != nil {
		return nil, fmt.Errorf("sql.Open: %v", err)
	}
	return db, err
}
func (p Postgres) executeQuery(database, query string, admin AdminCredentials) error {
	db, err := p.getDbConn(database, admin.Username, admin.Password)
	if err != nil {
		logrus.Fatalf("failed to open db connection: %s", err)
	}
	defer db.Close()
	_, err = db.Query(query)
	return err
}
func (p Postgres) executeExec(database, query string, admin AdminCredentials) error {
	db, err := p.getDbConn(database, admin.Username, admin.Password)
	if err != nil {
		logrus.Fatalf("failed to open db connection: %s", err)
	}
	defer db.Close()
	_, err = db.Exec(query)
	return err
}
func (p Postgres) isDbExist(admin AdminCredentials) bool {
	check := fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = '%s';", p.Database)
	return p.isRowExist("postgres", check, admin.Username, admin.Password)
}
func (p Postgres) isUserExist(admin AdminCredentials) bool {
	check := fmt.Sprintf("SELECT 1 FROM pg_user WHERE usename = '%s';", p.User)
	return p.isRowExist("postgres", check, admin.Username, admin.Password)
}