diff --git a/src/charm.py b/src/charm.py index 9e4f198941..837917b96e 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1428,6 +1428,14 @@ def _restart(self, event: RunWithLock) -> None: self.unit.status = BlockedStatus(error_message) return + try: + for attempt in Retrying(wait=wait_fixed(3), stop_after_delay=stop_after_delay(300)): + with attempt: + if not self._can_connect_to_postgresql: + assert False + except Exception: + logger.exception("Unable to reconnect to postgresql") + # Start or stop the pgBackRest TLS server service when TLS certificate change. self.backup.start_stop_pgbackrest_service() diff --git a/src/constants.py b/src/constants.py index 03b97ad213..fd42e0e247 100644 --- a/src/constants.py +++ b/src/constants.py @@ -36,7 +36,7 @@ SNAP_PACKAGES = [ ( POSTGRESQL_SNAP_NAME, - {"revision": {"aarch64": "110", "x86_64": "111"}, "channel": "14/stable"}, + {"revision": {"aarch64": "112", "x86_64": "113"}, "channel": "14/stable"}, ) ] diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index c913304e43..a8735a66e1 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -182,9 +182,11 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None: for unit_id in UNIT_IDS: host = get_unit_address(ops_test, f"{DATABASE_APP_NAME}/{unit_id}") logger.info("connecting to the database host: %s", host) - with db_connect(host, password) as connection: - settings_names = ["max_prepared_transactions", "shared_buffers", "lc_monetary"] - with connection.cursor() as cursor: + try: + with psycopg2.connect( + f"dbname='postgres' user='operator' host='{host}' password='{password}' connect_timeout=1" + ) as connection, connection.cursor() as cursor: + settings_names = ["max_prepared_transactions", "shared_buffers", "lc_monetary"] cursor.execute( sql.SQL("SELECT name,setting FROM pg_settings WHERE name IN ({});").format( sql.SQL(", ").join(sql.Placeholder() * len(settings_names)) @@ -193,12 +195,13 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None: ) records = cursor.fetchall() settings = convert_records_to_dict(records) - connection.close() - # Validate each configuration set by Patroni on PostgreSQL. - assert settings["max_prepared_transactions"] == "100" - assert settings["shared_buffers"] == "128" - assert settings["lc_monetary"] == "en_GB.utf8" + # Validate each configuration set by Patroni on PostgreSQL. + assert settings["max_prepared_transactions"] == "100" + assert settings["shared_buffers"] == "128" + assert settings["lc_monetary"] == "en_GB.utf8" + finally: + connection.close() @pytest.mark.group(1) diff --git a/tox.ini b/tox.ini index 3230fdae90..18edb1846a 100644 --- a/tox.ini +++ b/tox.ini @@ -26,7 +26,6 @@ allowlist_externals = charmcraft charmcraftcache mv - psycopg2-binary commands_pre = poetry export --only main,charm-libs --output requirements.txt commands =