diff --git a/pkg/client/database/postgres/executor.go b/pkg/client/database/postgres/executor.go index c4a8474c74a365..36dec4d8c4698a 100644 --- a/pkg/client/database/postgres/executor.go +++ b/pkg/client/database/postgres/executor.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strings" + "time" sdkpg "github.com/cloudquery/cq-provider-sdk/database/postgres" "github.com/hashicorp/go-hclog" @@ -36,6 +37,10 @@ func (e Executor) Validate(ctx context.Context) (bool, error) { return false, err } + if err := ValidatePostgresConnection(ctx, pool); err != nil { + return false, err + } + if err := ValidatePostgresVersion(ctx, pool, MinPostgresVersion); err != nil { return true, err } @@ -51,6 +56,14 @@ func (e Executor) Finalize(_ context.Context, err error) error { return err } +// ValidatePostgresConnection validates that we can actually connect to the postgres database. +func ValidatePostgresConnection(ctx context.Context, pool *pgxpool.Pool) error { + ctx, cancel := context.WithTimeout(ctx, time.Second*10) + defer cancel() + + return pool.Ping(ctx) +} + // queryRower helps with unit tests type queryRower interface { QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row diff --git a/pkg/client/database/timescale/timescale.go b/pkg/client/database/timescale/timescale.go index 41f8657c9a312b..962a849177e0e3 100644 --- a/pkg/client/database/timescale/timescale.go +++ b/pkg/client/database/timescale/timescale.go @@ -61,6 +61,10 @@ func (e Executor) Validate(ctx context.Context) (bool, error) { } defer pool.Close() + if err := postgres.ValidatePostgresConnection(ctx, pool); err != nil { + return false, err + } + if err := postgres.ValidatePostgresVersion(ctx, pool, postgres.MinPostgresVersion); err != nil { return false, err }