8
8
"os"
9
9
"os/exec"
10
10
"strconv"
11
+ "strings"
11
12
"time"
12
13
13
14
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
@@ -216,7 +217,13 @@ func (n *Node) PostInit(ctx context.Context) error {
216
217
// Use the Postgres user on boot, since our internal user may not have been created yet.
217
218
conn , err := n .NewLocalConnection (ctx , "postgres" , n .OperatorCredentials )
218
219
if err != nil {
219
- return fmt .Errorf ("failed to establish connection to member: %s" , err )
220
+ // Check to see if this is an authentication error.
221
+ if strings .Contains (err .Error (), "28P01" ) {
222
+ fmt .Println ("WARNING: `postgres` user password does not match the `OPERATOR_PASSWORD` secret" )
223
+ fmt .Printf ("HINT: Use `fly secrets set OPERATOR_PASSWORD=<password> --app %s` to resolve the issue\n " , n .AppName )
224
+ }
225
+
226
+ return fmt .Errorf ("failed to establish connection to local node: %s" , err )
220
227
}
221
228
defer func () { _ = conn .Close (ctx ) }()
222
229
@@ -283,6 +290,11 @@ func (n *Node) PostInit(ctx context.Context) error {
283
290
default :
284
291
return fmt .Errorf ("member has unknown role: %q" , member .Role )
285
292
}
293
+
294
+ // Ensure connection is closed.
295
+ if err := repConn .Close (ctx ); err != nil {
296
+ return fmt .Errorf ("failed to close connection: %s" , err )
297
+ }
286
298
} else {
287
299
// New member
288
300
@@ -335,11 +347,6 @@ func (n *Node) PostInit(ctx context.Context) error {
335
347
if err := issueRegistrationCert (); err != nil {
336
348
return fmt .Errorf ("failed to issue registration certificate: %s" , err )
337
349
}
338
-
339
- // Ensure connection is closed.
340
- if err := conn .Close (ctx ); err != nil {
341
- return fmt .Errorf ("failed to close connection: %s" , err )
342
- }
343
350
} else {
344
351
// Configure as standby
345
352
fmt .Println ("Registering standby" )
@@ -354,6 +361,11 @@ func (n *Node) PostInit(ctx context.Context) error {
354
361
}
355
362
}
356
363
364
+ // Ensure connection is closed.
365
+ if err := conn .Close (ctx ); err != nil {
366
+ return fmt .Errorf ("failed to close connection: %s" , err )
367
+ }
368
+
357
369
return nil
358
370
}
359
371
0 commit comments