|
36 | 36 |
|
37 | 37 | # Increment this PATCH version before using `charmcraft publish-lib` or reset
|
38 | 38 | # to 0 if you are raising the major API version
|
39 |
| -LIBPATCH = 35 |
| 39 | +LIBPATCH = 36 |
40 | 40 |
|
41 | 41 | INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles"
|
42 | 42 |
|
@@ -83,6 +83,10 @@ class PostgreSQLGetLastArchivedWALError(Exception):
|
83 | 83 | """Exception raised when retrieving last archived WAL fails."""
|
84 | 84 |
|
85 | 85 |
|
| 86 | +class PostgreSQLGetCurrentTimelineError(Exception): |
| 87 | + """Exception raised when retrieving current timeline id for the PostgreSQL unit fails.""" |
| 88 | + |
| 89 | + |
86 | 90 | class PostgreSQLGetPostgreSQLVersionError(Exception):
|
87 | 91 | """Exception raised when retrieving PostgreSQL version fails."""
|
88 | 92 |
|
@@ -419,6 +423,16 @@ def get_last_archived_wal(self) -> str:
|
419 | 423 | logger.error(f"Failed to get PostgreSQL last archived WAL: {e}")
|
420 | 424 | raise PostgreSQLGetLastArchivedWALError()
|
421 | 425 |
|
| 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 | + |
422 | 436 | def get_postgresql_text_search_configs(self) -> Set[str]:
|
423 | 437 | """Returns the PostgreSQL available text search configs.
|
424 | 438 |
|
|
0 commit comments