@@ -22,6 +22,7 @@ import (
2222 "github.com/docker/docker/api/types/container"
2323 "github.com/docker/docker/api/types/network"
2424 "github.com/docker/docker/client"
25+ specs "github.com/opencontainers/image-spec/specs-go/v1"
2526 "github.com/pkg/errors"
2627 "github.com/robfig/cron/v3"
2728
@@ -57,7 +58,8 @@ const (
5758 promoteTargetAction = "promote"
5859
5960 // WAL parsing constants.
60- walNameLen = 24
61+ walNameLen = 24
62+ pgVersion10 = 10
6163)
6264
6365var defaultRecoveryCfg = map [string ]string {
@@ -533,6 +535,7 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string,
533535 p .buildContainerConfig (clonePath , promoteImage , pwd , recoveryConfig [targetActionOption ]),
534536 hostConfig ,
535537 & network.NetworkingConfig {},
538+ & specs.Platform {},
536539 p .promoteContainerName (),
537540 )
538541
@@ -643,15 +646,17 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string,
643646func (p * PhysicalInitial ) getDSAFromWAL (ctx context.Context , pgVersion float64 , containerID , cloneDir string ) (string , error ) {
644647 log .Dbg (cloneDir )
645648
646- infos , err := ioutil .ReadDir (path .Join (cloneDir , "pg_wal" ))
649+ walDirectory := walDir (cloneDir , pgVersion )
650+
651+ infos , err := ioutil .ReadDir (walDirectory )
647652 if err != nil {
648653 return "" , errors .Wrap (err , "failed to read the pg_wal dir" )
649654 }
650655
651656 // Walk in the reverse order.
652657 for i := len (infos ) - 1 ; i >= 0 ; i -- {
653658 fileName := infos [i ].Name ()
654- walFilePath := path .Join (cloneDir , "pg_wal" , fileName )
659+ walFilePath := path .Join (walDirectory , fileName )
655660
656661 log .Dbg ("Look up into file: " , walFilePath )
657662
@@ -670,8 +675,18 @@ func (p *PhysicalInitial) getDSAFromWAL(ctx context.Context, pgVersion float64,
670675 return "" , nil
671676}
672677
678+ func walDir (cloneDir string , pgVersion float64 ) string {
679+ dir := "pg_wal"
680+
681+ if pgVersion < pgVersion10 {
682+ dir = "pg_xlog"
683+ }
684+
685+ return path .Join (cloneDir , dir )
686+ }
687+
673688func (p * PhysicalInitial ) parseWAL (ctx context.Context , containerID string , pgVersion float64 , walFilePath string ) string {
674- cmd := fmt . Sprintf ( "/usr/lib/postgresql/%g/bin/pg_waldump %s -r Transaction | tail -1" , pgVersion , walFilePath )
689+ cmd := walCommand ( pgVersion , walFilePath )
675690
676691 output , err := tools .ExecCommandWithOutput (ctx , p .dockerClient , containerID , types.ExecConfig {
677692 Cmd : []string {"sh" , "-c" , cmd },
@@ -691,6 +706,16 @@ func (p *PhysicalInitial) parseWAL(ctx context.Context, containerID string, pgVe
691706 return parseWALLine (output )
692707}
693708
709+ func walCommand (pgVersion float64 , walFilePath string ) string {
710+ walDumpUtil := "pg_waldump"
711+
712+ if pgVersion < pgVersion10 {
713+ walDumpUtil = "pg_xlogdump"
714+ }
715+
716+ return fmt .Sprintf ("/usr/lib/postgresql/%g/bin/%s %s -r Transaction | tail -1" , pgVersion , walDumpUtil , walFilePath )
717+ }
718+
694719func parseWALLine (line string ) string {
695720 const (
696721 commitToken = "COMMIT"
0 commit comments