patroni.postgresql.rewind module¶
-
class
patroni.postgresql.rewind.
REWIND_STATUS
¶ Bases:
enum.IntEnum
An enumeration.
-
CHECK
= 2¶
-
CHECKPOINT
= 1¶
-
FAILED
= 6¶
-
INITIAL
= 0¶
-
NEED
= 3¶
-
NOT_NEED
= 4¶
-
SUCCESS
= 5¶
-
-
class
patroni.postgresql.rewind.
Rewind
(postgresql: patroni.postgresql.Postgresql)¶ Bases:
object
-
_Rewind__checkpoint
(task: patroni.async_executor.CriticalTask, wakeup: Callable[[...], Any]) → None¶
-
__init__
(postgresql: patroni.postgresql.Postgresql) → None¶ Initialize self. See help(type(self)) for accurate signature.
-
_archive_ready_wals
() → None¶ Try to archive WALs that have .ready files just in case archive_mode was not set to ‘always’ before promote, while after it the WALs were recycled on the promoted replica. With this we prevent the entire loss of such WALs and the consequent old leader’s start failure.
-
_build_archiver_command
(command: str, wal_filename: str) → str¶ Replace placeholders in the given archiver command’s template. Applicable for archive_command and restore_command. Can also be used for archive_cleanup_command and recovery_end_command, however %r value is always set to 000000010000000000000001.
-
_check_timeline_and_lsn
(leader: Union[patroni.dcs.Leader, patroni.dcs.RemoteMember]) → None¶
-
_conn_kwargs
(member: Union[patroni.dcs.Leader, patroni.dcs.RemoteMember], auth: Dict[str, Any]) → Dict[str, Any]¶
-
_fetch_missing_wal
(restore_command: str, wal_filename: str) → bool¶
-
_find_missing_wal
(data: bytes) → Optional[str]¶
-
_get_checkpoint_end
(timeline: int, lsn: int) → int¶ Get the end of checkpoint record from WAL.
Note
The checkpoint record size in WAL depends on postgres major version and platform (memory alignment). Hence, the only reliable way to figure out where it ends, is to read the record from file with the help of
pg_waldump
and parse the output.We are trying to read two records, and expect that it will fail to read the second record with message:
fatal: error in WAL record at 0/182E220: invalid record length at 0/182E298: wanted 24, got 0; or
fatal: error in WAL record at 0/182E220: invalid record length at 0/182E298: expected at least 24, got 0
The error message contains information about LSN of the next record, which is exactly where checkpoint ends.
Parameters: - timeline – the checkpoint timeline from
pg_controldata
. - lsn – the checkpoint location as
int
frompg_controldata
.
Returns: the end of checkpoint record as
int
or0
if failed to parsepg_waldump
output.- timeline – the checkpoint timeline from
-
_get_local_timeline_lsn
() → Tuple[Optional[bool], Optional[int], Optional[int]]¶
-
_get_local_timeline_lsn_from_controldata
() → Tuple[Optional[bool], Optional[int], Optional[int]]¶
-
static
_log_primary_history
(history: List[Tuple[int, int, str]], i: int) → None¶
-
_maybe_clean_pg_replslot
() → None¶ Clean pg_replslot directory if pg version is less then 11 (pg_rewind deletes $PGDATA/pg_replslot content only since pg11).
-
can_rewind
¶ check if pg_rewind executable is there and that pg_controldata indicates we have either wal_log_hints or checksums turned on
-
can_rewind_or_reinitialize_allowed
¶
-
static
check_leader_has_run_checkpoint
(conn_kwargs: Dict[str, Any]) → Optional[str]¶
-
static
check_leader_is_not_in_recovery
(conn_kwargs: Dict[str, Any]) → Optional[bool]¶
-
checkpoint_after_promote
() → bool¶
-
cleanup_archive_status
() → None¶
-
static
configuration_allows_rewind
(data: Dict[str, str]) → bool¶
-
enabled
¶
-
ensure_checkpoint_after_promote
(wakeup: Callable[[...], Any]) → None¶ After promote issue a CHECKPOINT from a new thread and asynchronously check the result. In case if CHECKPOINT failed, just check that timeline in pg_control was updated.
-
ensure_clean_shutdown
() → Optional[bool]¶
-
execute
(leader: Union[patroni.dcs.Leader, patroni.dcs.RemoteMember]) → Optional[bool]¶
-
executed
¶
-
failed
¶
-
is_needed
¶
-
pg_rewind
(conn_kwargs: Dict[str, Any]) → bool¶ Do pg_rewind.
Note
If
pg_rewind
doesn’t support--restore-target-wal
parameter and exited with non zero code, Patroni will parse stderr/stdout to figure out if it failed due to a missing WAL file and will repeat an attempt after downloading the missing file usingrestore_command
.Parameters: conn_kwargs – dict
object with connection parameters.Returns: True
ifpg_rewind
finished successfully,False
otherwise.
-
read_postmaster_opts
() → Dict[str, str]¶ returns the list of option names/values from postgres.opts, Empty dict if read failed or no file
-
reset_state
() → None¶
-
rewind_or_reinitialize_needed_and_possible
(leader: Union[patroni.dcs.Leader, patroni.dcs.RemoteMember, None]) → bool¶
-
should_remove_data_directory_on_diverged_timelines
¶
-
single_user_mode
(communicate: Optional[Dict[str, Any]] = None, options: Optional[Dict[str, str]] = None) → Optional[int]¶ run a given command in a single-user mode. If the command is empty - then just start and stop
-
trigger_check_diverged_lsn
() → None¶
-