Skip to content

Commit 8801ef2

Browse files
authored
Merge pull request #60 from FilOzone/fix/robustify-db-connection-config
better pgx pool configs
2 parents 2318bf8 + 2141262 commit 8801ef2

File tree

1 file changed

+13
-1
lines changed
  • backend/indexer/internal/infrastructure/database

1 file changed

+13
-1
lines changed

backend/indexer/internal/infrastructure/database/postgres.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package database
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"pdp-explorer-indexer/internal/infrastructure/config"
89

@@ -16,6 +17,17 @@ type PostgresDB struct {
1617
}
1718

1819
func NewPostgresDB(cfg *config.Config) (*PostgresDB, error) {
20+
pgConfig, err := pgxpool.ParseConfig(cfg.DatabaseURL)
21+
if err != nil {
22+
return nil, fmt.Errorf("unable to parse database url: %w", err)
23+
}
24+
pgConfig.MaxConnLifetime = 30 * time.Minute
25+
pgConfig.MaxConns = 10
26+
pgConfig.MinConns = 2
27+
pgConfig.MaxConnIdleTime = 15 * time.Minute
28+
pgConfig.ConnConfig.ConnectTimeout = 30 * time.Second
29+
pgConfig.HealthCheckPeriod = 1 * time.Minute
30+
1931
pool, err := pgxpool.New(context.Background(), cfg.DatabaseURL)
2032
if err != nil {
2133
return nil, fmt.Errorf("unable to connect to database: %v", err)
@@ -131,6 +143,6 @@ func (p *PostgresDB) CleanupFinalizedData(ctx context.Context, currentBlockNumbe
131143
if err := p.CleanupFinalizedRoots(ctx, currentBlockNumber); err != nil {
132144
return fmt.Errorf("failed to cleanup finalized roots: %w", err)
133145
}
134-
146+
135147
return nil
136148
}

0 commit comments

Comments
 (0)