diff --git a/backend/internal/infrastructure/persistence/postgres/db.go b/backend/internal/infrastructure/persistence/postgres/db.go index 4103121..2cc4be4 100644 --- a/backend/internal/infrastructure/persistence/postgres/db.go +++ b/backend/internal/infrastructure/persistence/postgres/db.go @@ -15,7 +15,7 @@ import ( func New(dbURL string) (*pgxpool.Pool, error) { poolConfig, err := pgxpool.ParseConfig(dbURL) if err != nil { - return nil, fmt.Errorf("error while parsing connection string: %w", err) + return nil, fmt.Errorf("failed to parse connection string: %w", err) } poolConfig.MaxConns = 100 @@ -23,9 +23,13 @@ func New(dbURL string) (*pgxpool.Pool, error) { poolConfig.MaxConnLifetime = time.Hour poolConfig.HealthCheckPeriod = 30 * time.Second - db, err := pgxpool.NewWithConfig(context.Background(), poolConfig) + ctx := context.Background() + db, err := pgxpool.NewWithConfig(ctx, poolConfig) if err != nil { - return nil, fmt.Errorf("error while initializing DB connections pool: %w", err) + return nil, fmt.Errorf("failed to initialize DB connections pool: %w", err) + } + if err = db.Ping(ctx); err != nil { + return nil, fmt.Errorf("failed to ping database: %w", err) } return db, nil }