diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index f8f3ad2b23..071643841f 100644 --- a/lib/charms/postgresql_k8s/v0/postgresql.py +++ b/lib/charms/postgresql_k8s/v0/postgresql.py @@ -79,6 +79,10 @@ class PostgreSQLEnableDisableExtensionError(Exception): """Exception raised when enabling/disabling an extension fails.""" +class PostgreSQLGetLastArchivedWALError(Exception): + """Exception raised when retrieving last archived WAL fails.""" + + class PostgreSQLGetPostgreSQLVersionError(Exception): """Exception raised when retrieving PostgreSQL version fails.""" @@ -391,7 +395,7 @@ def get_last_archived_wal(self) -> str: return cursor.fetchone()[0] except psycopg2.Error as e: logger.error(f"Failed to get PostgreSQL last archived WAL: {e}") - raise PostgreSQLGetPostgreSQLVersionError() + raise PostgreSQLGetLastArchivedWALError() def get_postgresql_text_search_configs(self) -> Set[str]: """Returns the PostgreSQL available text search configs. diff --git a/src/backups.py b/src/backups.py index 217c17b8aa..c2e7be4dd9 100644 --- a/src/backups.py +++ b/src/backups.py @@ -594,12 +594,13 @@ def _on_s3_credential_changed(self, event: CredentialsChangedEvent): event.defer() return + if self.charm.unit.is_leader(): + self.charm.app_peer_data.pop("require-change-bucket-after-restore", None) + # Verify the s3 relation only on the primary. if not self.charm.is_primary: return - self.charm.app_peer_data.pop("require-change-bucket-after-restore", None) - try: self._create_bucket_if_not_exists() except (ClientError, ValueError): diff --git a/src/charm.py b/src/charm.py index 8a3e3ab41a..351609aad4 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1410,6 +1410,12 @@ def _set_primary_status_message(self) -> None: """Display 'Primary' in the unit status message if the current unit is the primary.""" try: if "require-change-bucket-after-restore" in self.app_peer_data: + if self.unit.is_leader(): + self.app_peer_data.update({ + "restoring-backup": "", + "restore-stanza": "", + "restore-to-time": "", + }) self.unit.status = BlockedStatus(MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET) return if self._patroni.get_primary(unit_name_pattern=True) == self.unit.name: diff --git a/tests/integration/test_backups.py b/tests/integration/test_backups.py index b813001cbd..adbf462105 100644 --- a/tests/integration/test_backups.py +++ b/tests/integration/test_backups.py @@ -287,7 +287,7 @@ async def test_restore_on_new_cluster(ops_test: OpsTest, github_secrets, charm) async with ops_test.fast_forward(): unit = ops_test.model.units.get(f"{database_app_name}/0") await ops_test.model.block_until( - lambda: unit.workload_status_message == ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE + lambda: unit.workload_status_message == MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET ) # Check that the backup was correctly restored by having only the first created table.