Filer Store: postgres backend support pgbouncer (#7077)

support pgbouncer
This commit is contained in:
Chris Lu
2025-08-03 11:56:04 -07:00
committed by GitHub
parent d49b44f2a4
commit 4fb7bbb215
7 changed files with 73 additions and 19 deletions

View File

@@ -8,7 +8,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/credential"
"github.com/seaweedfs/seaweedfs/weed/util"
_ "github.com/lib/pq"
_ "github.com/jackc/pgx/v5/stdlib"
)
func init() {
@@ -52,11 +52,12 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix
sslmode = "disable"
}
// Build connection string
// Build pgx-optimized connection string
// Note: prefer_simple_protocol=true is only needed for PgBouncer, not direct PostgreSQL connections
connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s search_path=%s",
hostname, port, username, password, database, sslmode, schema)
db, err := sql.Open("postgres", connStr)
db, err := sql.Open("pgx", connStr)
if err != nil {
return fmt.Errorf("failed to open database: %w", err)
}