diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2021-02-14 22:26:29 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-14 22:26:29 -0800 |
| commit | 50202d1391202c89bba475844e0b19eb1fd85955 (patch) | |
| tree | 0d610de204abf0c1b4958da0799debaffc21f8a3 /weed/filer/postgres2/postgres2_store.go | |
| parent | 8726ef34c1081d62bb0fa7348d56986a81acf9a0 (diff) | |
| parent | 7f458d5e78e380890771d925fee3df4f5f692e78 (diff) | |
| download | seaweedfs-50202d1391202c89bba475844e0b19eb1fd85955.tar.xz seaweedfs-50202d1391202c89bba475844e0b19eb1fd85955.zip | |
Merge pull request #1805 from LazyDBA247-Anyvision/master
better postgresql connection pool management
Diffstat (limited to 'weed/filer/postgres2/postgres2_store.go')
| -rw-r--r-- | weed/filer/postgres2/postgres2_store.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go index 94c760401..44487fd0e 100644 --- a/weed/filer/postgres2/postgres2_store.go +++ b/weed/filer/postgres2/postgres2_store.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "time" "github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/filer/abstract_sql" @@ -40,10 +41,11 @@ func (store *PostgresStore2) 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 *PostgresStore2) initialize(createTable, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen int) (err error) { +func (store *PostgresStore2) initialize(createTable, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { store.SupportBucketTable = true store.SqlGenerator = &postgres.SqlGenPostgres{ @@ -74,6 +76,7 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st 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) |
