|
|
@ -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 |
|
|
|
} |
|
|
|