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 @@ -1137,23 +1137,6 @@ def update_user_password(
1137
1137
if connection is not None :
1138
1138
connection .close ()
1139
1139
1140
- def is_restart_pending (self ) -> bool :
1141
- """Query pg_settings for pending restart."""
1142
- connection = None
1143
- try :
1144
- with self ._connect_to_database () as connection , connection .cursor () as cursor :
1145
- cursor .execute ("SELECT COUNT(*) FROM pg_settings WHERE pending_restart=True;" )
1146
- return cursor .fetchone ()[0 ] > 0
1147
- except psycopg2 .OperationalError :
1148
- logger .warning ("Failed to connect to PostgreSQL." )
1149
- return False
1150
- except psycopg2 .Error as e :
1151
- logger .error (f"Failed to check if restart is pending: { e } " )
1152
- return False
1153
- finally :
1154
- if connection :
1155
- connection .close ()
1156
-
1157
1140
@staticmethod
1158
1141
def build_postgresql_group_map (group_map : Optional [str ]) -> List [Tuple ]:
1159
1142
"""Build the PostgreSQL authorization group-map.
Original file line number Diff line number Diff line change @@ -2411,18 +2411,11 @@ def _handle_postgresql_restart_need(self) -> None:
2411
2411
self ._patroni .reload_patroni_configuration ()
2412
2412
except Exception as e :
2413
2413
logger .error (f"Reload patroni call failed! error: { e !s} " )
2414
- # Wait for some more time than the Patroni's loop_wait default value (10 seconds),
2415
- # which tells how much time Patroni will wait before checking the configuration
2416
- # file again to reload it.
2417
- try :
2418
- for attempt in Retrying (stop = stop_after_attempt (5 ), wait = wait_fixed (3 )):
2419
- with attempt :
2420
- restart_postgresql = restart_postgresql or self .postgresql .is_restart_pending ()
2421
- if not restart_postgresql :
2422
- raise Exception
2423
- except RetryError :
2424
- # Ignore the error, as it happens only to indicate that the configuration has not changed.
2425
- pass
2414
+
2415
+ restart_pending = self ._patroni .is_restart_pending ()
2416
+ logger .debug (f"Checking if restart pending: { restart_postgresql } or { restart_pending } " )
2417
+ restart_postgresql = restart_postgresql or restart_pending
2418
+
2426
2419
self .unit_peer_data .update ({"tls" : "enabled" if self .is_tls_enabled else "" })
2427
2420
self .postgresql_client_relation .update_endpoints ()
2428
2421
Original file line number Diff line number Diff line change @@ -439,6 +439,23 @@ def get_patroni_health(self) -> dict[str, str]:
439
439
440
440
return r .json ()
441
441
442
+ def is_restart_pending (self ) -> bool :
443
+ """Returns whether the Patroni/PostgreSQL restart pending."""
444
+ patroni_status = requests .get (
445
+ f"{ self ._patroni_url } /patroni" ,
446
+ verify = self .verify ,
447
+ timeout = API_REQUEST_TIMEOUT ,
448
+ auth = self ._patroni_auth ,
449
+ )
450
+ try :
451
+ pending_restart = patroni_status .json ()["pending_restart" ]
452
+ except KeyError :
453
+ pending_restart = False
454
+ pass
455
+ logger .debug (f"Patroni API is_restart_pending: { pending_restart } " )
456
+
457
+ return pending_restart
458
+
442
459
@property
443
460
def is_creating_backup (self ) -> bool :
444
461
"""Returns whether a backup is being created."""
You can’t perform that action at this time.
0 commit comments