File tree Expand file tree Collapse file tree 3 files changed +22
-29
lines changed
lib/charms/postgresql_k8s/v1 Expand file tree Collapse file tree 3 files changed +22
-29
lines changed Original file line number Diff line number Diff line change @@ -1322,23 +1322,6 @@ def update_user_password(
1322
1322
if connection is not None :
1323
1323
connection .close ()
1324
1324
1325
- def is_restart_pending (self ) -> bool :
1326
- """Query pg_settings for pending restart."""
1327
- connection = None
1328
- try :
1329
- with self ._connect_to_database () as connection , connection .cursor () as cursor :
1330
- cursor .execute ("SELECT COUNT(*) FROM pg_settings WHERE pending_restart=True;" )
1331
- return cursor .fetchone ()[0 ] > 0
1332
- except psycopg2 .OperationalError :
1333
- logger .warning ("Failed to connect to PostgreSQL." )
1334
- return False
1335
- except psycopg2 .Error as e :
1336
- logger .error (f"Failed to check if restart is pending: { e } " )
1337
- return False
1338
- finally :
1339
- if connection :
1340
- connection .close ()
1341
-
1342
1325
def database_exists (self , db : str ) -> bool :
1343
1326
"""Check whether specified database exists."""
1344
1327
connection = None
Original file line number Diff line number Diff line change @@ -2473,18 +2473,11 @@ def _handle_postgresql_restart_need(self) -> None:
2473
2473
self ._patroni .reload_patroni_configuration ()
2474
2474
except Exception as e :
2475
2475
logger .error (f"Reload patroni call failed! error: { e !s} " )
2476
- # Wait for some more time than the Patroni's loop_wait default value (10 seconds),
2477
- # which tells how much time Patroni will wait before checking the configuration
2478
- # file again to reload it.
2479
- try :
2480
- for attempt in Retrying (stop = stop_after_attempt (5 ), wait = wait_fixed (3 )):
2481
- with attempt :
2482
- restart_postgresql = restart_postgresql or self .postgresql .is_restart_pending ()
2483
- if not restart_postgresql :
2484
- raise Exception
2485
- except RetryError :
2486
- # Ignore the error, as it happens only to indicate that the configuration has not changed.
2487
- pass
2476
+
2477
+ restart_pending = self ._patroni .is_restart_pending ()
2478
+ logger .debug (f"Checking if restart pending: { restart_postgresql } or { restart_pending } " )
2479
+ restart_postgresql = restart_postgresql or restart_pending
2480
+
2488
2481
self .unit_peer_data .update ({"tls" : "enabled" if self .is_tls_enabled else "" })
2489
2482
self .postgresql_client_relation .update_endpoints ()
2490
2483
Original file line number Diff line number Diff line change @@ -464,6 +464,23 @@ def get_patroni_health(self) -> dict[str, str]:
464
464
465
465
return r .json ()
466
466
467
+ def is_restart_pending (self ) -> bool :
468
+ """Returns whether the Patroni/PostgreSQL restart pending."""
469
+ patroni_status = requests .get (
470
+ f"{ self ._patroni_url } /patroni" ,
471
+ verify = self .verify ,
472
+ timeout = API_REQUEST_TIMEOUT ,
473
+ auth = self ._patroni_auth ,
474
+ )
475
+ try :
476
+ pending_restart = patroni_status .json ()["pending_restart" ]
477
+ except KeyError :
478
+ pending_restart = False
479
+ pass
480
+ logger .debug (f"Patroni API is_restart_pending: { pending_restart } " )
481
+
482
+ return pending_restart
483
+
467
484
@property
468
485
def is_creating_backup (self ) -> bool :
469
486
"""Returns whether a backup is being created."""
You can’t perform that action at this time.
0 commit comments