Skip to content

Commit ef0bac4

Browse files
authored
Fix creating the PGUSER at pg_autoctl create postgres time. (#950)
1 parent de5eb89 commit ef0bac4

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/bin/pg_autoctl/keeper_pg_init.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,16 @@ create_database_and_extension(Keeper *keeper)
10111011
return false;
10121012
}
10131013

1014+
/*
1015+
* ensure_postgres_service_is_running reset our connection string to update
1016+
* pgSetup cache with new Postgres pid and other information, but we really
1017+
* want to make sure we connect with no username still (bootstrap user) and
1018+
* to the template1 database.
1019+
*/
1020+
strlcpy(initPgSetup.username, "", NAMEDATALEN);
1021+
strlcpy(initPgSetup.dbname, "template1", NAMEDATALEN);
1022+
local_postgres_init(&initPostgres, &initPgSetup);
1023+
10141024
/*
10151025
* If username was set in the setup and doesn't exist we need to create it.
10161026
*/
@@ -1028,7 +1038,7 @@ create_database_and_extension(Keeper *keeper)
10281038
return false;
10291039
}
10301040

1031-
if (strcmp(pguser, pgSetup->username) == 0)
1041+
if (!IS_EMPTY_STRING_BUFFER(pguser))
10321042
{
10331043
unsetenv("PGUSER");
10341044
}
@@ -1048,10 +1058,12 @@ create_database_and_extension(Keeper *keeper)
10481058
}
10491059

10501060
/* reinstall the PGUSER value now that the user has been created. */
1051-
if (strcmp(pguser, pgSetup->username) == 0)
1061+
if (!IS_EMPTY_STRING_BUFFER(pguser))
10521062
{
10531063
setenv("PGUSER", pguser, 1);
10541064
}
1065+
1066+
log_info("CREATE USER %s", pgSetup->username);
10551067
}
10561068

10571069
/*

src/bin/pg_autoctl/pgsql.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ pgsql_create_user(PGSQL *pgsql, const char *userName, const char *password,
22492249
if (password)
22502250
{
22512251
/* show the statement before we append the password */
2252-
log_debug("Running command on Postgres: %s PASSWORD '*****';", query->data);
2252+
log_debug("%s PASSWORD '*****';", query->data);
22532253

22542254
escapedIdentifier = PQescapeLiteral(connection, password, strlen(password));
22552255
if (escapedIdentifier == NULL)
@@ -2267,7 +2267,7 @@ pgsql_create_user(PGSQL *pgsql, const char *userName, const char *password,
22672267
}
22682268
else
22692269
{
2270-
log_debug("Running command on Postgres: %s;", query->data);
2270+
log_debug("%s;", query->data);
22712271
}
22722272

22732273
/* memory allocation could have failed while building string */

0 commit comments

Comments
 (0)