mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Merge pull request #1805 from LazyDBA247-Anyvision/master
better postgresql connection pool management
This commit is contained in:
commit
50202d1391
|
@ -160,6 +160,7 @@ schema = ""
|
||||||
sslmode = "disable"
|
sslmode = "disable"
|
||||||
connection_max_idle = 100
|
connection_max_idle = 100
|
||||||
connection_max_open = 100
|
connection_max_open = 100
|
||||||
|
connection_max_lifetime_seconds = 0
|
||||||
|
|
||||||
[postgres2]
|
[postgres2]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
@ -181,6 +182,7 @@ schema = ""
|
||||||
sslmode = "disable"
|
sslmode = "disable"
|
||||||
connection_max_idle = 100
|
connection_max_idle = 100
|
||||||
connection_max_open = 100
|
connection_max_open = 100
|
||||||
|
connection_max_lifetime_seconds = 0
|
||||||
|
|
||||||
[cassandra]
|
[cassandra]
|
||||||
# CREATE TABLE filemeta (
|
# CREATE TABLE filemeta (
|
||||||
|
|
|
@ -3,6 +3,7 @@ package postgres
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer"
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer/abstract_sql"
|
"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.GetString(prefix+"sslmode"),
|
||||||
configuration.GetInt(prefix+"connection_max_idle"),
|
configuration.GetInt(prefix+"connection_max_idle"),
|
||||||
configuration.GetInt(prefix+"connection_max_open"),
|
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.SupportBucketTable = false
|
||||||
store.SqlGenerator = &SqlGenPostgres{
|
store.SqlGenerator = &SqlGenPostgres{
|
||||||
|
@ -71,6 +73,7 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int
|
||||||
|
|
||||||
store.DB.SetMaxIdleConns(maxIdle)
|
store.DB.SetMaxIdleConns(maxIdle)
|
||||||
store.DB.SetMaxOpenConns(maxOpen)
|
store.DB.SetMaxOpenConns(maxOpen)
|
||||||
|
store.DB.SetConnMaxLifetime(time.Duration(maxLifetimeSeconds) * time.Second)
|
||||||
|
|
||||||
if err = store.DB.Ping(); err != nil {
|
if err = store.DB.Ping(); err != nil {
|
||||||
return fmt.Errorf("connect to %s error:%v", sqlUrl, err)
|
return fmt.Errorf("connect to %s error:%v", sqlUrl, err)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer"
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer/abstract_sql"
|
"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.GetString(prefix+"sslmode"),
|
||||||
configuration.GetInt(prefix+"connection_max_idle"),
|
configuration.GetInt(prefix+"connection_max_idle"),
|
||||||
configuration.GetInt(prefix+"connection_max_open"),
|
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.SupportBucketTable = true
|
||||||
store.SqlGenerator = &postgres.SqlGenPostgres{
|
store.SqlGenerator = &postgres.SqlGenPostgres{
|
||||||
|
@ -74,6 +76,7 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st
|
||||||
|
|
||||||
store.DB.SetMaxIdleConns(maxIdle)
|
store.DB.SetMaxIdleConns(maxIdle)
|
||||||
store.DB.SetMaxOpenConns(maxOpen)
|
store.DB.SetMaxOpenConns(maxOpen)
|
||||||
|
store.DB.SetConnMaxLifetime(time.Duration(maxLifetimeSeconds) * time.Second)
|
||||||
|
|
||||||
if err = store.DB.Ping(); err != nil {
|
if err = store.DB.Ping(); err != nil {
|
||||||
return fmt.Errorf("connect to %s error:%v", sqlUrl, err)
|
return fmt.Errorf("connect to %s error:%v", sqlUrl, err)
|
||||||
|
|
Loading…
Reference in a new issue