Skip to content

Commit

Permalink
restore postgresql.conf, adopt sequence diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Aug 22, 2023
1 parent 66ccfa3 commit c58310c
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 11 deletions.
20 changes: 12 additions & 8 deletions cmd/internal/database/postgres/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

const (
postgresHBAConf = "pg_hba.conf"
postgresqlConf = "postgresql.conf"
postgresConfigCmd = "pg_config"
postgresUpgradeCmd = "pg_upgrade"
postgresInitDBCmd = "initdb"
Expand Down Expand Up @@ -137,14 +138,17 @@ func (db *Postgres) Upgrade() error {
}
db.log.Infow("new database directory initialized")

// restore old pg_hba.conf
pgHBAConf, err := os.ReadFile(path.Join(db.datadir, postgresHBAConf))
if err != nil {
return err
}
err = os.WriteFile(path.Join(newDataDirTemp, postgresHBAConf), pgHBAConf, 0600)
if err != nil {
return err
// restore old pg_hba.conf and postgresql.conf
for _, config := range []string{postgresHBAConf, postgresqlConf} {
db.log.Infow("restore old configuration into new datadir", "config", config)
cfg, err := os.ReadFile(path.Join(db.datadir, config))
if err != nil {
return err
}
err = os.WriteFile(path.Join(newDataDirTemp, config), cfg, 0600)
if err != nil {
return err
}
}

err = db.restoreOldPostgresBinaries(db.datadir, newDataDirTemp)
Expand Down
Loading

0 comments on commit c58310c

Please sign in to comment.