diff options
| author | LazyDBA247-Anyvision <yonin@anyvision.co> | 2021-02-15 07:45:09 +0200 |
|---|---|---|
| committer | LazyDBA247-Anyvision <yonin@anyvision.co> | 2021-02-15 07:45:09 +0200 |
| commit | 7f458d5e78e380890771d925fee3df4f5f692e78 (patch) | |
| tree | 27504329a544b84b097ebb97e7ed4886075d4cd6 /weed/filer/postgres/postgres_store.go | |
| parent | 0bc3a1f9e88baca5f592d50ca028d169c86f0dc8 (diff) | |
| download | seaweedfs-7f458d5e78e380890771d925fee3df4f5f692e78.tar.xz seaweedfs-7f458d5e78e380890771d925fee3df4f5f692e78.zip | |
better postgres connection pool management
adding SetConnMaxLifetime configuration (https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime)
to enable refresh of stale connections.
Diffstat (limited to 'weed/filer/postgres/postgres_store.go')
| -rw-r--r-- | weed/filer/postgres/postgres_store.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index 6e0d05315..75d80e44a 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -3,6 +3,7 @@ package postgres import ( "database/sql" "fmt" + "time" "github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/filer/abstract_sql" @@ -37,10 +38,11 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix configuration.GetString(prefix+"sslmode"), configuration.GetInt(prefix+"connection_max_idle"), configuration.GetInt(prefix+"connection_max_open"), + configuration.GetInt(prefix+"connection_max_lifetime_seconds"), ) } -func (store *PostgresStore) initialize(user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen int) (err error) { +func (store *PostgresStore) initialize(user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { store.SupportBucketTable = false store.SqlGenerator = &SqlGenPostgres{ @@ -71,6 +73,7 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int store.DB.SetMaxIdleConns(maxIdle) store.DB.SetMaxOpenConns(maxOpen) + store.DB.SetConnMaxLifetime(time.Duration(maxLifetimeSeconds) * time.Second) if err = store.DB.Ping(); err != nil { return fmt.Errorf("connect to %s error:%v", sqlUrl, err) |
