@@ -65,12 +65,13 @@ func NewNode() (*Node, error) {
6565 Password : os .Getenv ("SU_PASSWORD" ),
6666 }
6767
68- // Superuser
68+ // Postgres user
6969 node .OperatorCredentials = admin.Credential {
7070 Username : "postgres" ,
7171 Password : os .Getenv ("OPERATOR_PASSWORD" ),
7272 }
7373
74+ // Repmgr user
7475 node .ReplCredentials = admin.Credential {
7576 Username : "repmgr" ,
7677 Password : os .Getenv ("REPL_PASSWORD" ),
@@ -212,7 +213,8 @@ func (n *Node) PostInit(ctx context.Context) error {
212213 return fmt .Errorf ("unrecoverable zombie" )
213214 }
214215
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 )
216218 if err != nil {
217219 return fmt .Errorf ("failed to establish connection to member: %s" , err )
218220 }
@@ -355,11 +357,6 @@ func (n *Node) PostInit(ctx context.Context) error {
355357 return nil
356358}
357359
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-
363360func (n * Node ) setupCredentials (ctx context.Context , conn * pgx.Conn ) error {
364361 requiredCredentials := []admin.Credential {
365362 n .OperatorCredentials ,
@@ -370,6 +367,12 @@ func (n *Node) setupCredentials(ctx context.Context, conn *pgx.Conn) error {
370367 return admin .ManageDefaultUsers (ctx , conn , requiredCredentials )
371368}
372369
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+
373376func openConnection (parentCtx context.Context , host string , database string , creds admin.Credential ) (* pgx.Conn , error ) {
374377 ctx , cancel := context .WithTimeout (parentCtx , 10 * time .Second )
375378 defer cancel ()
0 commit comments