From 51b4963e2eaa6caff8ed4702453b9af371cf6914 Mon Sep 17 00:00:00 2001 From: LazyDBA247-Anyvision Date: Sun, 14 Feb 2021 13:14:36 +0200 Subject: postgres2 & memsql2 add escape (quote identifiers) for the dynamic sql so tables (collections) with special characters will work. --- weed/filer/postgres2/postgres2_store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'weed/filer/postgres2/postgres2_store.go') diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go index 82552376f..94c760401 100644 --- a/weed/filer/postgres2/postgres2_store.go +++ b/weed/filer/postgres2/postgres2_store.go @@ -48,7 +48,7 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st store.SupportBucketTable = true store.SqlGenerator = &postgres.SqlGenPostgres{ CreateTableSqlTemplate: createTable, - DropTableSqlTemplate: "drop table %s", + DropTableSqlTemplate: `drop table "%s"`, } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) -- cgit v1.2.3 From 7f458d5e78e380890771d925fee3df4f5f692e78 Mon Sep 17 00:00:00 2001 From: LazyDBA247-Anyvision Date: Mon, 15 Feb 2021 07:45:09 +0200 Subject: better postgres connection pool management adding SetConnMaxLifetime configuration (https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime) to enable refresh of stale connections. --- weed/filer/postgres2/postgres2_store.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'weed/filer/postgres2/postgres2_store.go') 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) -- cgit v1.2.3 From 3f8b0da6772ea99b600303bb1ad3f6430a45290a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 17 Feb 2021 02:13:50 -0800 Subject: filer: do not print password on error fix https://github.com/chrislusf/seaweedfs/issues/1809 --- weed/filer/postgres2/postgres2_store.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'weed/filer/postgres2/postgres2_store.go') diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go index 44487fd0e..4b5fbc8cf 100644 --- a/weed/filer/postgres2/postgres2_store.go +++ b/weed/filer/postgres2/postgres2_store.go @@ -57,21 +57,25 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st if user != "" { sqlUrl += " user=" + user } + adaptedSqlUrl := sqlUrl if password != "" { sqlUrl += " password=" + password + adaptedSqlUrl += " password=ADAPTED" } if database != "" { sqlUrl += " dbname=" + database + adaptedSqlUrl += " dbname=" + database } if schema != "" { sqlUrl += " search_path=" + schema + adaptedSqlUrl += " search_path=" + schema } var dbErr error store.DB, dbErr = sql.Open("postgres", sqlUrl) if dbErr != nil { store.DB.Close() store.DB = nil - return fmt.Errorf("can not connect to %s error:%v", sqlUrl, err) + return fmt.Errorf("can not connect to %s error:%v", adaptedSqlUrl, err) } store.DB.SetMaxIdleConns(maxIdle) -- cgit v1.2.3 From 3575d41009e4367658e75e6ae780c6260b80daf9 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 17 Feb 2021 20:57:08 -0800 Subject: go fmt --- weed/filer/postgres2/postgres2_store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'weed/filer/postgres2/postgres2_store.go') diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go index 4b5fbc8cf..92893bf7a 100644 --- a/weed/filer/postgres2/postgres2_store.go +++ b/weed/filer/postgres2/postgres2_store.go @@ -50,7 +50,7 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st store.SupportBucketTable = true store.SqlGenerator = &postgres.SqlGenPostgres{ CreateTableSqlTemplate: createTable, - DropTableSqlTemplate: `drop table "%s"`, + DropTableSqlTemplate: `drop table "%s"`, } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) -- cgit v1.2.3