@@ -23,8 +23,11 @@ import (
23
23
)
24
24
25
25
const (
26
- // waitPostgresTimeout defines timeout to wait Postgres ready.
27
- waitPostgresTimeout = 360
26
+ // waitPostgresConnectionTimeout defines timeout to wait for Postgres initial connection.
27
+ waitPostgresConnectionTimeout = 120
28
+
29
+ // waitPostgresStartTimeout defines timeout to wait for Postgres start.
30
+ waitPostgresStartTimeout = 360
28
31
29
32
// checkPostgresStatusPeriod defines period to check Postgres status.
30
33
checkPostgresStatusPeriod = 500
@@ -56,9 +59,10 @@ func Start(r runners.Runner, c *resources.AppConfig) error {
56
59
return errors .Wrap (err , "failed to run container" )
57
60
}
58
61
59
- // Waiting for server to become ready and promoting if needed.
62
+ // Waiting for server to become ready and promote if needed.
60
63
first := true
61
64
cnt := 0
65
+ waitPostgresTimeout := waitPostgresConnectionTimeout
62
66
63
67
for {
64
68
logs , err := docker .GetLogs (r , c , logsMinuteWindow )
@@ -75,9 +79,6 @@ func Start(r runners.Runner, c *resources.AppConfig) error {
75
79
76
80
out , err := runSimpleSQL ("select pg_is_in_recovery()" , c )
77
81
78
- log .Dbg ("sql: out: " , out )
79
- log .Err ("sql: err: " , err )
80
-
81
82
if err == nil {
82
83
// Server does not need promotion if it is not in recovery.
83
84
if out == "f" || out == "false" {
@@ -88,6 +89,9 @@ func Start(r runners.Runner, c *resources.AppConfig) error {
88
89
if out == "t" && first {
89
90
log .Dbg ("Postgres instance needs promotion." )
90
91
92
+ // Increase Postgres start timeout for promotion.
93
+ waitPostgresTimeout = waitPostgresStartTimeout
94
+
91
95
first = false
92
96
93
97
_ , err = pgctlPromote (r , c )
@@ -99,16 +103,18 @@ func Start(r runners.Runner, c *resources.AppConfig) error {
99
103
return err
100
104
}
101
105
}
106
+ } else {
107
+ log .Err ("Currently cannot connect to Postgres: " , out , err )
102
108
}
103
109
104
110
cnt ++
105
111
106
- if cnt > waitPostgresTimeout { // 3 minutes
112
+ if cnt > waitPostgresTimeout {
107
113
if runnerErr := Stop (r , c ); runnerErr != nil {
108
114
log .Err (runnerErr )
109
115
}
110
116
111
- return errors .Wrap (err , "postgres could not be promoted within 3 minutes " )
117
+ return errors .Wrap (err , "postgres start timeout " )
112
118
}
113
119
114
120
time .Sleep (checkPostgresStatusPeriod * time .Millisecond )
0 commit comments