Skip to content

Commit 95ad074

Browse files
authored
[DPE-5561] Timeline Management (#629)
* Timelines management. * Disabled failing unit tests. * Improvements from the K8s PR. * Add automatic timeline selection with the single 'restore-to-time' parameter. * Fix docs. * Revert "Disabled failing unit tests." This reverts commit e5cec66. * Parameter validation improvement. * Unit tests.
1 parent 55d4720 commit 95ad074

File tree

10 files changed

+683
-385
lines changed

10 files changed

+683
-385
lines changed

lib/charms/postgresql_k8s/v0/postgresql.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3838
# to 0 if you are raising the major API version
39-
LIBPATCH = 35
39+
LIBPATCH = 36
4040

4141
INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles"
4242

@@ -83,6 +83,10 @@ class PostgreSQLGetLastArchivedWALError(Exception):
8383
"""Exception raised when retrieving last archived WAL fails."""
8484

8585

86+
class PostgreSQLGetCurrentTimelineError(Exception):
87+
"""Exception raised when retrieving current timeline id for the PostgreSQL unit fails."""
88+
89+
8690
class PostgreSQLGetPostgreSQLVersionError(Exception):
8791
"""Exception raised when retrieving PostgreSQL version fails."""
8892

@@ -419,6 +423,16 @@ def get_last_archived_wal(self) -> str:
419423
logger.error(f"Failed to get PostgreSQL last archived WAL: {e}")
420424
raise PostgreSQLGetLastArchivedWALError()
421425

426+
def get_current_timeline(self) -> str:
427+
"""Get the timeline id for the current PostgreSQL unit."""
428+
try:
429+
with self._connect_to_database() as connection, connection.cursor() as cursor:
430+
cursor.execute("SELECT timeline_id FROM pg_control_checkpoint();")
431+
return cursor.fetchone()[0]
432+
except psycopg2.Error as e:
433+
logger.error(f"Failed to get PostgreSQL current timeline id: {e}")
434+
raise PostgreSQLGetCurrentTimelineError()
435+
422436
def get_postgresql_text_search_configs(self) -> Set[str]:
423437
"""Returns the PostgreSQL available text search configs.
424438

0 commit comments

Comments
 (0)