Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Aug 20, 2023
1 parent a19b6ce commit 230d69e
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions cmd/internal/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,27 +245,11 @@ func (db *Postgres) Upgrade() error {
// return nil
// }

// run the pg_upgrade command

// mkdir /data/postgres-new
newDataDirTemp := path.Join("/data", "postgres-new")
err = os.MkdirAll(newDataDirTemp, 0700)
if err != nil {
db.log.Infow("unable to create new datadir, skipping upgrade", "error", err)
return nil
}

// run the pg_upgrade command as postgres user
pgUser, err := user.Lookup("postgres")
if err != nil {
return err
}

chownCMD := exec.Command("chown", "-R", "postgres", newDataDirTemp)
err = chownCMD.Run()
if err != nil {
return err
}
// initdb -D /data/postgres-new
uid, err := strconv.Atoi(pgUser.Uid)
if err != nil {
return err
Expand All @@ -274,6 +258,16 @@ func (db *Postgres) Upgrade() error {
if err != nil {
return err
}

// mkdir /data/postgres-new
newDataDirTemp := path.Join("/data", "postgres-new")
err = os.MkdirAll(newDataDirTemp, 0700)
if err != nil {
db.log.Infow("unable to create new datadir, skipping upgrade", "error", err)
return nil
}

// initdb -D /data/postgres-new
cmd := exec.Command(postgresInitDBCmd, "-D", newDataDirTemp)
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down

0 comments on commit 230d69e

Please sign in to comment.