SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
Allow postgresql to use standard environment variables for connection (#3413)
John W Higgins3afda0c89c8f
diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.goindex ed38babcd1..cacdbd864f 100644--- a/weed/filer/postgres/postgres_store.go+++ b/weed/filer/postgres/postgres_store.go@@ -3,6 +3,7 @@ package postgresimport ("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, usUpsertQueryTemplate: 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.goindex d95b1c424c..01e3e9c878 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, enableUUpsertQueryTemplate: 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}