Skip to content

Commit ec055df

Browse files
author
Rachel Heaton
authored
Bug/837 No need to checkpoint and restart if pg is not running (#839)
* No need to checkpoint and restart if pg is not running When updating replication settings, no need to attempt a checkpoint and restart when postgres keeper is not running. Just start the service. Fixes #837 * Small test fix: re.match only checks a single line re.search will not give us false positives in this test
1 parent 37a2496 commit ec055df

3 files changed

Lines changed: 40 additions & 16 deletions

File tree

src/bin/pg_autoctl/keeper.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -973,17 +973,29 @@ keeper_ensure_configuration(Keeper *keeper, bool postgresNotRunningIsOk)
973973
log_info("Replication settings at \"%s\" have changed, "
974974
"restarting Postgres", upstreamConfPath);
975975

976-
if (!pgsql_checkpoint(&(postgres->sqlClient)))
976+
if (pg_setup_is_running(pgSetup))
977977
{
978-
log_warn("Failed to CHECKPOINT before restart, "
979-
"see above for details");
980-
}
978+
if (!pgsql_checkpoint(&(postgres->sqlClient)))
979+
{
980+
log_warn("Failed to CHECKPOINT before restart, "
981+
"see above for details");
982+
}
981983

982-
if (!keeper_restart_postgres(keeper))
984+
if (!keeper_restart_postgres(keeper))
985+
{
986+
log_error("Failed to restart Postgres to enable new "
987+
"replication settings, see above for details");
988+
return false;
989+
}
990+
}
991+
else
983992
{
984-
log_error("Failed to restart Postgres to enable new "
985-
"replication settings, see above for details");
986-
return false;
993+
if (!ensure_postgres_service_is_running(postgres))
994+
{
995+
log_error("Failed to start Postgres with new "
996+
"replication settings, see above for details");
997+
return false;
998+
}
987999
}
9881000
}
9891001
}

tests/pgautofailover_utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,16 +655,20 @@ def show_uri(self, json=False):
655655
out, err, ret = command.execute("show uri", "show", "uri")
656656
return out
657657

658-
def logs(self):
658+
def logs(self, log_type=""):
659659
log_string = ""
660660
if self.running():
661661
out, err, ret = self.stop_pg_autoctl()
662-
log_string += f"STDOUT OF PG_AUTOCTL FOR {self.datadir}:\n"
663-
log_string += f"{self.pg_autoctl.cmd}\n{out}\n"
664-
log_string += f"STDERR OF PG_AUTOCTL FOR {self.datadir}:\n{err}\n"
665-
666-
pglogs = self.get_postgres_logs()
667-
log_string += f"POSTGRES LOGS FOR {self.datadir}:\n{pglogs}\n"
662+
if not log_type or (log_type == "STDOUT"):
663+
log_string += f"STDOUT OF PG_AUTOCTL FOR {self.datadir}:\n"
664+
log_string += f"{self.pg_autoctl.cmd}\n{out}\n"
665+
if not log_type or (log_type == "STDERR"):
666+
log_string += (
667+
f"STDERR OF PG_AUTOCTL FOR {self.datadir}:\n{err}\n"
668+
)
669+
if not log_type or (log_type == "POSTGRES"):
670+
pglogs = self.get_postgres_logs()
671+
log_string += f"POSTGRES LOGS FOR {self.datadir}:\n{pglogs}\n"
668672
return log_string
669673

670674
def get_events_str(self):

tests/test_auth.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def test_003_init_secondary():
6868
node1.get_synchronous_standby_names_local(),
6969
"ANY 1 (pgautofailover_standby_2)",
7070
)
71+
logs = node2.logs("STDERR")
72+
match = re.search(
73+
"Failed to connect to .*, retrying until the server is ready", logs
74+
)
75+
if match:
76+
print("Found connection failure in logs: ", match[0])
77+
assert not match
78+
node2.run()
7179

7280

7381
def test_004_failover():
@@ -89,7 +97,7 @@ def test_005_logging_of_passwords():
8997
assert "password=****" in logs
9098
# We are still logging passwords when the pguri is incomplete and when printing settings,
9199
# so assert that it's not there in other cases:
92-
assert not re.match(
100+
assert not re.search(
93101
"^(?!primary_conninfo|Failed to find).*%s.*$" % replication_password,
94102
logs,
95103
)

0 commit comments

Comments
 (0)