@@ -65,12 +65,13 @@ func NewNode() (*Node, error) {
65
65
Password : os .Getenv ("SU_PASSWORD" ),
66
66
}
67
67
68
- // Superuser
68
+ // Postgres user
69
69
node .OperatorCredentials = admin.Credential {
70
70
Username : "postgres" ,
71
71
Password : os .Getenv ("OPERATOR_PASSWORD" ),
72
72
}
73
73
74
+ // Repmgr user
74
75
node .ReplCredentials = admin.Credential {
75
76
Username : "repmgr" ,
76
77
Password : os .Getenv ("REPL_PASSWORD" ),
@@ -212,7 +213,8 @@ func (n *Node) PostInit(ctx context.Context) error {
212
213
return fmt .Errorf ("unrecoverable zombie" )
213
214
}
214
215
215
- conn , err := n .NewLocalConnection (ctx , "postgres" )
216
+ // Use the Postgres user on boot, since our internal user may not have been created yet.
217
+ conn , err := n .NewLocalConnection (ctx , "postgres" , n .OperatorCredentials )
216
218
if err != nil {
217
219
return fmt .Errorf ("failed to establish connection to member: %s" , err )
218
220
}
@@ -355,11 +357,6 @@ func (n *Node) PostInit(ctx context.Context) error {
355
357
return nil
356
358
}
357
359
358
- func (n * Node ) NewLocalConnection (ctx context.Context , database string ) (* pgx.Conn , error ) {
359
- host := net .JoinHostPort (n .PrivateIP , strconv .Itoa (n .Port ))
360
- return openConnection (ctx , host , database , n .OperatorCredentials )
361
- }
362
-
363
360
func (n * Node ) setupCredentials (ctx context.Context , conn * pgx.Conn ) error {
364
361
requiredCredentials := []admin.Credential {
365
362
n .OperatorCredentials ,
@@ -370,6 +367,12 @@ func (n *Node) setupCredentials(ctx context.Context, conn *pgx.Conn) error {
370
367
return admin .ManageDefaultUsers (ctx , conn , requiredCredentials )
371
368
}
372
369
370
+ // NewLocalConnection opens up a new connection using the flypgadmin user.
371
+ func (n * Node ) NewLocalConnection (ctx context.Context , database string , creds admin.Credential ) (* pgx.Conn , error ) {
372
+ host := net .JoinHostPort (n .PrivateIP , strconv .Itoa (n .Port ))
373
+ return openConnection (ctx , host , database , creds )
374
+ }
375
+
373
376
func openConnection (parentCtx context.Context , host string , database string , creds admin.Credential ) (* pgx.Conn , error ) {
374
377
ctx , cancel := context .WithTimeout (parentCtx , 10 * time .Second )
375
378
defer cancel ()
0 commit comments