Skip to content

Commit d38b21b

Browse files
committed
Merge branch '271-stop-postgres' into 'master'
fix: stop Postgres after logical restore (#271): Closes #271 See merge request postgres-ai/database-lab!305
2 parents 3b5e5a6 + 09ff0a4 commit d38b21b

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

pkg/retrieval/engine/postgres/logical/dump.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ func (d *DumpJob) Run(ctx context.Context) (err error) {
333333
if err := tools.ExecCommand(ctx, d.dockerClient, dumpCont.ID, types.ExecConfig{Cmd: analyzeCmd}); err != nil {
334334
return errors.Wrap(err, "failed to recalculate statistics after restore")
335335
}
336+
337+
if err := tools.StopPostgres(ctx, d.dockerClient, dumpCont.ID, dataDir, tools.DefaultStopTimeout); err != nil {
338+
return errors.Wrap(err, "failed to stop Postgres instance")
339+
}
336340
}
337341

338342
log.Msg("Dumping job has been finished")

pkg/retrieval/engine/postgres/logical/restore.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ func (r *RestoreJob) Run(ctx context.Context) (err error) {
221221
return errors.Wrap(err, "failed to recalculate statistics after restore")
222222
}
223223

224+
if err := tools.StopPostgres(ctx, r.dockerClient, restoreCont.ID, dataDir, tools.DefaultStopTimeout); err != nil {
225+
return errors.Wrap(err, "failed to stop Postgres instance")
226+
}
227+
224228
log.Msg("Restoring job has been finished")
225229

226230
return nil

pkg/retrieval/engine/postgres/snapshot/physical.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,7 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string,
632632
return errors.Wrap(err, "failed to store prepared configuration")
633633
}
634634

635-
const pgStopTimeout = 600
636-
637-
if err := tools.StopPostgres(ctx, p.dockerClient, promoteCont.ID, clonePath, pgStopTimeout); err != nil {
635+
if err := tools.StopPostgres(ctx, p.dockerClient, promoteCont.ID, clonePath, tools.DefaultStopTimeout); err != nil {
638636
log.Msg("Failed to stop Postgres", err)
639637
tools.PrintContainerLogs(ctx, p.dockerClient, promoteCont.ID)
640638
}

pkg/retrieval/engine/postgres/tools/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const (
4141
essentialLogsInterval = "10s"
4242

4343
// DefaultStopTimeout defines the default timeout for Postgres stop.
44-
DefaultStopTimeout = 60
44+
DefaultStopTimeout = 600
4545

4646
// ViewLogsCmd tells the command to view docker container logs.
4747
ViewLogsCmd = "docker logs --since 1m -f"

0 commit comments

Comments
 (0)