88 "os"
99 "os/exec"
1010 "strconv"
11+ "strings"
1112 "time"
1213
1314 "github.com/fly-apps/postgres-flex/internal/flypg/admin"
@@ -216,7 +217,13 @@ func (n *Node) PostInit(ctx context.Context) error {
216217 // Use the Postgres user on boot, since our internal user may not have been created yet.
217218 conn , err := n .NewLocalConnection (ctx , "postgres" , n .OperatorCredentials )
218219 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 )
220227 }
221228 defer func () { _ = conn .Close (ctx ) }()
222229
@@ -283,6 +290,11 @@ func (n *Node) PostInit(ctx context.Context) error {
283290 default :
284291 return fmt .Errorf ("member has unknown role: %q" , member .Role )
285292 }
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+ }
286298 } else {
287299 // New member
288300
@@ -335,11 +347,6 @@ func (n *Node) PostInit(ctx context.Context) error {
335347 if err := issueRegistrationCert (); err != nil {
336348 return fmt .Errorf ("failed to issue registration certificate: %s" , err )
337349 }
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- }
343350 } else {
344351 // Configure as standby
345352 fmt .Println ("Registering standby" )
@@ -354,6 +361,11 @@ func (n *Node) PostInit(ctx context.Context) error {
354361 }
355362 }
356363
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+
357369 return nil
358370}
359371
0 commit comments