@@ -22,6 +22,7 @@ import (
22
22
"github.com/docker/docker/api/types/container"
23
23
"github.com/docker/docker/api/types/network"
24
24
"github.com/docker/docker/client"
25
+ specs "github.com/opencontainers/image-spec/specs-go/v1"
25
26
"github.com/pkg/errors"
26
27
"github.com/robfig/cron/v3"
27
28
@@ -57,7 +58,8 @@ const (
57
58
promoteTargetAction = "promote"
58
59
59
60
// WAL parsing constants.
60
- walNameLen = 24
61
+ walNameLen = 24
62
+ pgVersion10 = 10
61
63
)
62
64
63
65
var defaultRecoveryCfg = map [string ]string {
@@ -533,6 +535,7 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string,
533
535
p .buildContainerConfig (clonePath , promoteImage , pwd , recoveryConfig [targetActionOption ]),
534
536
hostConfig ,
535
537
& network.NetworkingConfig {},
538
+ & specs.Platform {},
536
539
p .promoteContainerName (),
537
540
)
538
541
@@ -643,15 +646,17 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string,
643
646
func (p * PhysicalInitial ) getDSAFromWAL (ctx context.Context , pgVersion float64 , containerID , cloneDir string ) (string , error ) {
644
647
log .Dbg (cloneDir )
645
648
646
- infos , err := ioutil .ReadDir (path .Join (cloneDir , "pg_wal" ))
649
+ walDirectory := walDir (cloneDir , pgVersion )
650
+
651
+ infos , err := ioutil .ReadDir (walDirectory )
647
652
if err != nil {
648
653
return "" , errors .Wrap (err , "failed to read the pg_wal dir" )
649
654
}
650
655
651
656
// Walk in the reverse order.
652
657
for i := len (infos ) - 1 ; i >= 0 ; i -- {
653
658
fileName := infos [i ].Name ()
654
- walFilePath := path .Join (cloneDir , "pg_wal" , fileName )
659
+ walFilePath := path .Join (walDirectory , fileName )
655
660
656
661
log .Dbg ("Look up into file: " , walFilePath )
657
662
@@ -670,8 +675,18 @@ func (p *PhysicalInitial) getDSAFromWAL(ctx context.Context, pgVersion float64,
670
675
return "" , nil
671
676
}
672
677
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
+
673
688
func (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 )
675
690
676
691
output , err := tools .ExecCommandWithOutput (ctx , p .dockerClient , containerID , types.ExecConfig {
677
692
Cmd : []string {"sh" , "-c" , cmd },
@@ -691,6 +706,16 @@ func (p *PhysicalInitial) parseWAL(ctx context.Context, containerID string, pgVe
691
706
return parseWALLine (output )
692
707
}
693
708
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
+
694
719
func parseWALLine (line string ) string {
695
720
const (
696
721
commitToken = "COMMIT"
0 commit comments