Skip to content

Commit

Permalink
recreate postgres binary directories
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Aug 21, 2023
1 parent f88ec6e commit 7b6e46c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/internal/database/postgres/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"os/user"
"path"
"path/filepath"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -146,6 +147,11 @@ func (db *Postgres) Upgrade() error {
return err
}

err = db.restoreOldPostgresBinaries(db.datadir, newDataDirTemp)
if err != nil {
return err
}

newPostgresBindir, err := db.getBindir(postgresConfigCmd)
if err != nil {
return fmt.Errorf("unable to detect bindir of actual postgres %w", err)
Expand Down Expand Up @@ -272,3 +278,25 @@ func (db *Postgres) copyPostgresBinaries() error {
}
return nil
}

func (db *Postgres) restoreOldPostgresBinaries(src, dst string) error {
err := filepath.WalkDir(src, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !strings.HasPrefix(d.Name(), "pg-bin-v") {
return nil
}
db.log.Infow("copying postgres binaries from old datadir to new datadir", "from", path, "to", dst)
copy := exec.Command("cp", "-av", path, dst)
copy.Stdout = os.Stdout
copy.Stderr = os.Stderr
err = copy.Run()
if err != nil {
return fmt.Errorf("unable to copy pgbindir %w", err)
}

return nil
})
return err
}

0 comments on commit 7b6e46c

Please sign in to comment.