From eb7929a9714d5d4ea8d9d70f58198b09bc459ead Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 1 Sep 2020 00:21:19 -0700 Subject: rename filer2 to filer --- weed/filer/postgres/postgres_store.go | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 weed/filer/postgres/postgres_store.go (limited to 'weed/filer/postgres/postgres_store.go') diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go new file mode 100644 index 000000000..4544c8416 --- /dev/null +++ b/weed/filer/postgres/postgres_store.go @@ -0,0 +1,75 @@ +package postgres + +import ( + "database/sql" + "fmt" + + "github.com/chrislusf/seaweedfs/weed/filer" + "github.com/chrislusf/seaweedfs/weed/filer/abstract_sql" + "github.com/chrislusf/seaweedfs/weed/util" + _ "github.com/lib/pq" +) + +const ( + CONNECTION_URL_PATTERN = "host=%s port=%d user=%s sslmode=%s connect_timeout=30" +) + +func init() { + filer.Stores = append(filer.Stores, &PostgresStore{}) +} + +type PostgresStore struct { + abstract_sql.AbstractSqlStore +} + +func (store *PostgresStore) GetName() string { + return "postgres" +} + +func (store *PostgresStore) Initialize(configuration util.Configuration, prefix string) (err error) { + return store.initialize( + configuration.GetString(prefix+"username"), + configuration.GetString(prefix+"password"), + configuration.GetString(prefix+"hostname"), + configuration.GetInt(prefix+"port"), + configuration.GetString(prefix+"database"), + configuration.GetString(prefix+"sslmode"), + configuration.GetInt(prefix+"connection_max_idle"), + configuration.GetInt(prefix+"connection_max_open"), + ) +} + +func (store *PostgresStore) initialize(user, password, hostname string, port int, database, sslmode string, maxIdle, maxOpen int) (err error) { + + store.SqlInsert = "INSERT INTO filemeta (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)" + store.SqlUpdate = "UPDATE filemeta SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4" + store.SqlFind = "SELECT meta FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" + store.SqlDelete = "DELETE FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" + store.SqlDeleteFolderChildren = "DELETE FROM filemeta WHERE dirhash=$1 AND directory=$2" + store.SqlListExclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like CONCAT($4,'%')ORDER BY NAME ASC LIMIT $5" + store.SqlListInclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like CONCAT($4,'%') ORDER BY NAME ASC LIMIT $5" + + sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, user, sslmode) + if password != "" { + sqlUrl += " password=" + password + } + if database != "" { + sqlUrl += " dbname=" + database + } + 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) + } + + store.DB.SetMaxIdleConns(maxIdle) + store.DB.SetMaxOpenConns(maxOpen) + + if err = store.DB.Ping(); err != nil { + return fmt.Errorf("connect to %s error:%v", sqlUrl, err) + } + + return nil +} -- cgit v1.2.3 From b0c7de186da98ee9e2d9ac4f9cdd86347031d263 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 12 Sep 2020 13:37:03 -0700 Subject: filer: fix postgres prefixed directory listing problem fix https://github.com/chrislusf/seaweedfs/issues/1465 --- weed/filer/postgres/postgres_store.go | 4 ++-- 1 file changed, 2 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 4544c8416..c41700d17 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -46,8 +46,8 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int store.SqlFind = "SELECT meta FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" store.SqlDelete = "DELETE FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" store.SqlDeleteFolderChildren = "DELETE FROM filemeta WHERE dirhash=$1 AND directory=$2" - store.SqlListExclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like CONCAT($4,'%')ORDER BY NAME ASC LIMIT $5" - store.SqlListInclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like CONCAT($4,'%') ORDER BY NAME ASC LIMIT $5" + store.SqlListExclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" + store.SqlListInclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, user, sslmode) if password != "" { -- cgit v1.2.3 From b81359823fdd8dca0edf812303cd1d441e0dce3f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 22 Oct 2020 14:27:47 -0700 Subject: postgres: support empty user --- weed/filer/postgres/postgres_store.go | 7 +++++-- 1 file changed, 5 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 c41700d17..2325568fe 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -11,7 +11,7 @@ import ( ) const ( - CONNECTION_URL_PATTERN = "host=%s port=%d user=%s sslmode=%s connect_timeout=30" + CONNECTION_URL_PATTERN = "host=%s port=%d sslmode=%s connect_timeout=30" ) func init() { @@ -49,7 +49,10 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int store.SqlListExclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" store.SqlListInclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" - sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, user, sslmode) + sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) + if user != "" { + sqlUrl += " user=" + user + } if password != "" { sqlUrl += " password=" + password } -- cgit v1.2.3 From 4c5b752b040bbbee34fdc1db61fe6e210fb11961 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 19 Jan 2021 13:53:16 -0800 Subject: restructuring sql stores --- weed/filer/postgres/postgres_store.go | 43 +++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 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 2325568fe..783f27c10 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -14,6 +14,41 @@ const ( CONNECTION_URL_PATTERN = "host=%s port=%d sslmode=%s connect_timeout=30" ) +type SqlGenPostgres struct { +} + +var ( + _ = abstract_sql.SqlGenerator(&SqlGenPostgres{}) +) + +func (gen *SqlGenPostgres) GetSqlInsert(bucket string) string { + return "INSERT INTO filemeta (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)" +} + +func (gen *SqlGenPostgres) GetSqlUpdate(bucket string) string { + return "UPDATE filemeta SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4" +} + +func (gen *SqlGenPostgres) GetSqlFind(bucket string) string { + return "SELECT meta FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" +} + +func (gen *SqlGenPostgres) GetSqlDelete(bucket string) string { + return "DELETE FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" +} + +func (gen *SqlGenPostgres) GetSqlDeleteFolderChildren(bucket string) string { + return "DELETE FROM filemeta WHERE dirhash=$1 AND directory=$2" +} + +func (gen *SqlGenPostgres) GetSqlListExclusive(bucket string) string { + return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" +} + +func (gen *SqlGenPostgres) GetSqlListInclusive(bucket string) string { + return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" +} + func init() { filer.Stores = append(filer.Stores, &PostgresStore{}) } @@ -41,13 +76,7 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix func (store *PostgresStore) initialize(user, password, hostname string, port int, database, sslmode string, maxIdle, maxOpen int) (err error) { - store.SqlInsert = "INSERT INTO filemeta (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)" - store.SqlUpdate = "UPDATE filemeta SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4" - store.SqlFind = "SELECT meta FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" - store.SqlDelete = "DELETE FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" - store.SqlDeleteFolderChildren = "DELETE FROM filemeta WHERE dirhash=$1 AND directory=$2" - store.SqlListExclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" - store.SqlListInclusive = "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" + store.SqlGenerator = &SqlGenPostgres{} sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) if user != "" { -- cgit v1.2.3 From 93b3adba9864dd278a778ccfe2165bcadb010574 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 19 Jan 2021 15:55:51 -0800 Subject: fix bucket creation --- weed/filer/postgres/postgres_store.go | 16 +++++++++++++++- 1 file changed, 15 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 783f27c10..8c36b8672 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -15,6 +15,8 @@ const ( ) type SqlGenPostgres struct { + createTableSqlTemplate string + dropTableSqlTemplate string } var ( @@ -49,6 +51,14 @@ func (gen *SqlGenPostgres) GetSqlListInclusive(bucket string) string { return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" } +func (gen *SqlGenPostgres) GetSqlCreateTable(bucket string) string { + return fmt.Sprintf(gen.createTableSqlTemplate, bucket) +} + +func (gen *SqlGenPostgres) GetSqlDropTable(bucket string) string { + return fmt.Sprintf(gen.dropTableSqlTemplate, bucket) +} + func init() { filer.Stores = append(filer.Stores, &PostgresStore{}) } @@ -76,7 +86,11 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix func (store *PostgresStore) initialize(user, password, hostname string, port int, database, sslmode string, maxIdle, maxOpen int) (err error) { - store.SqlGenerator = &SqlGenPostgres{} + store.SupportBucketTable = false + store.SqlGenerator = &SqlGenPostgres{ + createTableSqlTemplate: "", + dropTableSqlTemplate: "drop table %s", + } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) if user != "" { -- cgit v1.2.3 From d5add83e85da0c61fe107842e7dd82b52af2bcdb Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 19 Jan 2021 18:07:29 -0800 Subject: filer store: add postgres2 --- weed/filer/postgres/postgres_store.go | 55 +++++------------------------------ 1 file changed, 7 insertions(+), 48 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 8c36b8672..27c6278c7 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -14,51 +14,6 @@ const ( CONNECTION_URL_PATTERN = "host=%s port=%d sslmode=%s connect_timeout=30" ) -type SqlGenPostgres struct { - createTableSqlTemplate string - dropTableSqlTemplate string -} - -var ( - _ = abstract_sql.SqlGenerator(&SqlGenPostgres{}) -) - -func (gen *SqlGenPostgres) GetSqlInsert(bucket string) string { - return "INSERT INTO filemeta (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)" -} - -func (gen *SqlGenPostgres) GetSqlUpdate(bucket string) string { - return "UPDATE filemeta SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4" -} - -func (gen *SqlGenPostgres) GetSqlFind(bucket string) string { - return "SELECT meta FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" -} - -func (gen *SqlGenPostgres) GetSqlDelete(bucket string) string { - return "DELETE FROM filemeta WHERE dirhash=$1 AND name=$2 AND directory=$3" -} - -func (gen *SqlGenPostgres) GetSqlDeleteFolderChildren(bucket string) string { - return "DELETE FROM filemeta WHERE dirhash=$1 AND directory=$2" -} - -func (gen *SqlGenPostgres) GetSqlListExclusive(bucket string) string { - return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" -} - -func (gen *SqlGenPostgres) GetSqlListInclusive(bucket string) string { - return "SELECT NAME, meta FROM filemeta WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5" -} - -func (gen *SqlGenPostgres) GetSqlCreateTable(bucket string) string { - return fmt.Sprintf(gen.createTableSqlTemplate, bucket) -} - -func (gen *SqlGenPostgres) GetSqlDropTable(bucket string) string { - return fmt.Sprintf(gen.dropTableSqlTemplate, bucket) -} - func init() { filer.Stores = append(filer.Stores, &PostgresStore{}) } @@ -78,18 +33,19 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix configuration.GetString(prefix+"hostname"), configuration.GetInt(prefix+"port"), configuration.GetString(prefix+"database"), + configuration.GetString(prefix+"schema"), configuration.GetString(prefix+"sslmode"), configuration.GetInt(prefix+"connection_max_idle"), configuration.GetInt(prefix+"connection_max_open"), ) } -func (store *PostgresStore) initialize(user, password, hostname string, port int, database, sslmode string, maxIdle, maxOpen int) (err error) { +func (store *PostgresStore) initialize(user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen int) (err error) { store.SupportBucketTable = false store.SqlGenerator = &SqlGenPostgres{ - createTableSqlTemplate: "", - dropTableSqlTemplate: "drop table %s", + CreateTableSqlTemplate: "", + DropTableSqlTemplate: "drop table %s", } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) @@ -102,6 +58,9 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int if database != "" { sqlUrl += " dbname=" + database } + if schema != "" { + sqlUrl += " search_path=" + schema + } var dbErr error store.DB, dbErr = sql.Open("postgres", sqlUrl) if dbErr != nil { -- cgit v1.2.3 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 From 4a02389eb08c3b7fcb7fe157f51e526df5220ac4 Mon Sep 17 00:00:00 2001 From: LazyDBA247-Anyvision Date: Mon, 29 Mar 2021 09:58:13 +0300 Subject: Adding custom insertQuery support for postgres/2 mysql/2 --- weed/filer/postgres/postgres_store.go | 4 +++- 1 file changed, 3 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 9e4ff7c32..ea9b1c71e 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -29,6 +29,7 @@ func (store *PostgresStore) GetName() string { func (store *PostgresStore) Initialize(configuration util.Configuration, prefix string) (err error) { return store.initialize( + configuration.GetString(prefix+"insertQuery"), configuration.GetString(prefix+"username"), configuration.GetString(prefix+"password"), configuration.GetString(prefix+"hostname"), @@ -42,12 +43,13 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix ) } -func (store *PostgresStore) initialize(user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { +func (store *PostgresStore) initialize(insertQuery, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { store.SupportBucketTable = false store.SqlGenerator = &SqlGenPostgres{ CreateTableSqlTemplate: "", DropTableSqlTemplate: `drop table "%s"`, + InsertQueryTemplate: insertQuery, } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) -- cgit v1.2.3 From 4c51e6a6605ce4592957c047c73c345a0a12bae3 Mon Sep 17 00:00:00 2001 From: LazyDBA247-Anyvision Date: Tue, 30 Mar 2021 00:32:03 +0300 Subject: add enableUpsert=true and rename config to upsertQuery --- weed/filer/postgres/postgres_store.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 ea9b1c71e..498c98f65 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -29,7 +29,8 @@ func (store *PostgresStore) GetName() string { func (store *PostgresStore) Initialize(configuration util.Configuration, prefix string) (err error) { return store.initialize( - configuration.GetString(prefix+"insertQuery"), + configuration.GetString(prefix+"upsertQuery"), + configuration.GetString(prefix+"enableUpsert"), configuration.GetString(prefix+"username"), configuration.GetString(prefix+"password"), configuration.GetString(prefix+"hostname"), @@ -43,13 +44,16 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix ) } -func (store *PostgresStore) initialize(insertQuery, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { +func (store *PostgresStore) initialize(upsertQuery, enableUpsert, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { store.SupportBucketTable = false + if !enableUpsert { + upsertQuery = "" + } store.SqlGenerator = &SqlGenPostgres{ CreateTableSqlTemplate: "", DropTableSqlTemplate: `drop table "%s"`, - InsertQueryTemplate: insertQuery, + UpsertQueryTemplate: upsertQuery, } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) -- cgit v1.2.3 From 7f44d953b56dc74281b6de3dcac184d97c9715f1 Mon Sep 17 00:00:00 2001 From: LazyDBA247-Anyvision Date: Tue, 30 Mar 2021 01:36:02 +0300 Subject: fix GetBool --- weed/filer/postgres/postgres_store.go | 4 ++-- 1 file changed, 2 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 498c98f65..21b79d1fe 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -30,7 +30,7 @@ func (store *PostgresStore) GetName() string { func (store *PostgresStore) Initialize(configuration util.Configuration, prefix string) (err error) { return store.initialize( configuration.GetString(prefix+"upsertQuery"), - configuration.GetString(prefix+"enableUpsert"), + configuration.GetBool(prefix+"enableUpsert"), configuration.GetString(prefix+"username"), configuration.GetString(prefix+"password"), configuration.GetString(prefix+"hostname"), @@ -44,7 +44,7 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix ) } -func (store *PostgresStore) initialize(upsertQuery, enableUpsert, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { +func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { store.SupportBucketTable = false if !enableUpsert { -- cgit v1.2.3 From 8e404a1433fe437de22b3356176cf36eb3719018 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 2 Apr 2021 02:22:26 -0700 Subject: go fmt --- 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 21b79d1fe..a1e16a92a 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -48,7 +48,7 @@ func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, us store.SupportBucketTable = false if !enableUpsert { - upsertQuery = "" + upsertQuery = "" } store.SqlGenerator = &SqlGenPostgres{ CreateTableSqlTemplate: "", -- cgit v1.2.3