diff --git a/cmd/internal/database/postgres/postgres.go b/cmd/internal/database/postgres/postgres.go index ec9f3b2..a32581a 100644 --- a/cmd/internal/database/postgres/postgres.go +++ b/cmd/internal/database/postgres/postgres.go @@ -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 @@ -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 {