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/postgres/postgres_store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'weed/filer/postgres/postgres_store.go') diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index 27c6278c7..6e0d05315 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -45,7 +45,7 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int store.SupportBucketTable = false store.SqlGenerator = &SqlGenPostgres{ CreateTableSqlTemplate: "", - 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/postgres/postgres_store.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'weed/filer/postgres/postgres_store.go') 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) -- 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/postgres/postgres_store.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'weed/filer/postgres/postgres_store.go') diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index 75d80e44a..9e4ff7c32 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -47,28 +47,32 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int store.SupportBucketTable = false store.SqlGenerator = &SqlGenPostgres{ CreateTableSqlTemplate: "", - DropTableSqlTemplate: `drop table "%s"`, + DropTableSqlTemplate: `drop table "%s"`, } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) 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