From 3d3d22dc069af2ceee0fe565374b2b50b91456a9 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 10 Dec 2025 19:02:24 +0800 Subject: [PATCH] fix: Fix local PostgreSQL database backup failure (#11295) --- agent/utils/postgresql/client/local.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/agent/utils/postgresql/client/local.go b/agent/utils/postgresql/client/local.go index 1b6f178b1..7f830c432 100644 --- a/agent/utils/postgresql/client/local.go +++ b/agent/utils/postgresql/client/local.go @@ -134,11 +134,7 @@ func (r *Local) Backup(info BackupInfo) error { defer outfile.Close() global.LOG.Infof("start to pg_dump | gzip > %s.gzip", info.TargetDir+"/"+info.FileName) - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(info.Timeout*uint(time.Second))) - defer cancel() - cmd := exec.CommandContext( - ctx, - "docker", "exec", "-i", r.ContainerName, + cmd := exec.Command("docker", "exec", "-i", r.ContainerName, "sh", "-c", fmt.Sprintf("PGPASSWORD=%s pg_dump -F c -U %s -d %s", r.Password, r.Username, info.Name), ) @@ -161,9 +157,7 @@ func (r *Local) Recover(info RecoverInfo) error { fi, _ := os.Open(info.SourceFile) defer fi.Close() - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(info.Timeout*uint(time.Second))) - defer cancel() - cmd := exec.CommandContext(ctx, "docker", "exec", "-i", r.ContainerName, "sh", "-c", + cmd := exec.Command("docker", "exec", "-i", r.ContainerName, "sh", "-c", fmt.Sprintf("PGPASSWORD=%s pg_restore -F c -c --if-exists --no-owner -U %s -d %s", r.Password, r.Username, info.Name), ) if strings.HasSuffix(info.SourceFile, ".gz") {