Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: pg_dump password option (#1472)

h3n4l494ba900758b
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.go
index ba37fa3709..3e4841b67d 100644
--- a/plugin/db/pg/pg.go
+++ b/plugin/db/pg/pg.go
@@ -923,8 +923,6 @@ func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database st
args = append(args, fmt.Sprintf("--username=%s", driver.config.Username))
if driver.config.Password == "" {
args = append(args, "--no-password")
- } else {
- args = append(args, fmt.Sprintf("--password=%s", driver.config.Password))
}
args = append(args, fmt.Sprintf("--host=%s", driver.config.Host))
args = append(args, fmt.Sprintf("--port=%s", driver.config.Port))
@@ -936,6 +934,10 @@ func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database st
args = append(args, database)
pgDumpPath := filepath.Join(driver.pgInstanceDir, "bin", "pg_dump")
cmd := exec.Command(pgDumpPath, args...)
+ if driver.config.Password != "" {
+ // Unlike MySQL, PostgreSQL does not support specifying commands in commands, we can do this by means of environment variables.
+ cmd.Env = append(cmd.Env, fmt.Sprintf("PGPASSWORD=%s", driver.config.Password))
+ }
cmd.Stderr = os.Stderr
r, err := cmd.StdoutPipe()
if err != nil {