Skip to content

Commit

Permalink
Fix monitor postgres not starting up the first time (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Jul 2, 2021
1 parent 18229bc commit ca79fba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
13 changes: 11 additions & 2 deletions src/bin/pg_autoctl/fsm_transition.c
Original file line number Diff line number Diff line change
Expand Up @@ -1463,10 +1463,19 @@ fsm_init_from_standby(Keeper *keeper)
/*
* fsm_drop_node is called to finish dropping a node on the client side.
*
* Nothing to do here, really.
* This stops postgres and updates the postgres state file to say that postgres
* should be stopped. It also cleans up any existing init file. Not doing these
* two things can confuse a possible future re-init of the node.
*/
bool
fsm_drop_node(Keeper *keeper)
{
return true;
KeeperConfig *config = &(keeper->config);
if (!fsm_stop_postgres(keeper))
{
/* errors have already been logged */
return false;
}

return unlink_file(config->pathnames.init);
}
16 changes: 16 additions & 0 deletions src/bin/pg_autoctl/keeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,22 @@ keeper_register_and_init(Keeper *keeper, NodeState initialState)
goto rollback;
}

/*
* If we dropped a primary using --force, it's possible that the postgres
* state file still says that postgres should be running. In that case
* postgres would probably be running now. The problem is that our
* fsm_init_primary transation errors out when a postgres is running during
* initialization. So if we were dropped and this is the first time
* create is run after that, then we first stop postgres and record this
* in our postgres state file.
*/
if (keeper->state.current_role == DROPPED_STATE &&
!file_exists(keeper->config.pathnames.init))
{
log_info("Making sure postgres was stopped, when it was previously dropped");
ensure_postgres_service_is_stopped(&keeper->postgres);
}

/*
* Leave a track record that we're ok to initialize in PGDATA, so that in
* case of `pg_autoctl create` being interrupted, we may resume operations
Expand Down
10 changes: 0 additions & 10 deletions src/bin/pg_autoctl/service_postgres_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,6 @@ service_postgres_ctl_loop(LocalPostgresServer *postgres)
/* make sure to initialize the expected Postgres status to unknown */
pgStatus->pgExpectedStatus = PG_EXPECTED_STATUS_UNKNOWN;

if (pg_setup_pgdata_exists(pgSetup))
{
if (!local_postgres_set_status_path(postgres, true))
{
log_error("Failed to clean-up postgres state file pathname, "
"see above for details.");
exit(EXIT_CODE_BAD_STATE);
}
}

for (;;)
{
int status;
Expand Down

0 comments on commit ca79fba

Please sign in to comment.