aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn W Higgins <wishdev@gmail.com>2022-08-07 00:58:53 -0700
committerGitHub <noreply@github.com>2022-08-07 00:58:53 -0700
commit3afda0c89c8faa584423b6b1b488cd18d1d42a88 (patch)
tree055245ca376ae151b0c72fc45b86eae09cd0d436
parent1a4bf0dcb5852c62070fe9627b7e63c5d55bb460 (diff)
downloadseaweedfs-3afda0c89c8faa584423b6b1b488cd18d1d42a88.tar.xz
seaweedfs-3afda0c89c8faa584423b6b1b488cd18d1d42a88.zip
Allow postgresql to use standard environment variables for connection (#3413)
-rw-r--r--weed/filer/postgres/postgres_store.go16
-rw-r--r--weed/filer/postgres2/postgres2_store.go16
2 files changed, 22 insertions, 10 deletions
diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go
index ed38babcd..cacdbd864 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"
+ "strconv"
"time"
_ "github.com/lib/pq"
@@ -11,10 +12,6 @@ import (
"github.com/seaweedfs/seaweedfs/weed/util"
)
-const (
- CONNECTION_URL_PATTERN = "host=%s port=%d sslmode=%s connect_timeout=30"
-)
-
func init() {
filer.Stores = append(filer.Stores, &PostgresStore{})
}
@@ -56,7 +53,16 @@ func (store *PostgresStore) initialize(upsertQuery string, enableUpsert bool, us
UpsertQueryTemplate: upsertQuery,
}
- sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)
+ sqlUrl := "connect_timeout=30"
+ if hostname != "" {
+ sqlUrl += " host=" + hostname
+ }
+ if port != 0 {
+ sqlUrl += " port=" + strconv.Itoa(port)
+ }
+ if sslmode != "" {
+ sqlUrl += " sslmode=" + sslmode
+ }
if user != "" {
sqlUrl += " user=" + user
}
diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go
index d95b1c424..01e3e9c87 100644
--- a/weed/filer/postgres2/postgres2_store.go
+++ b/weed/filer/postgres2/postgres2_store.go
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
+ "strconv"
"time"
_ "github.com/lib/pq"
@@ -13,10 +14,6 @@ import (
"github.com/seaweedfs/seaweedfs/weed/util"
)
-const (
- CONNECTION_URL_PATTERN = "host=%s port=%d sslmode=%s connect_timeout=30"
-)
-
var _ filer.BucketAware = (*PostgresStore2)(nil)
func init() {
@@ -61,7 +58,16 @@ func (store *PostgresStore2) initialize(createTable, upsertQuery string, enableU
UpsertQueryTemplate: upsertQuery,
}
- sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)
+ sqlUrl := "connect_timeout=30"
+ if hostname != "" {
+ sqlUrl += " host=" + hostname
+ }
+ if port != 0 {
+ sqlUrl += " port=" + strconv.Itoa(port)
+ }
+ if sslmode != "" {
+ sqlUrl += " sslmode=" + sslmode
+ }
if user != "" {
sqlUrl += " user=" + user
}