barman.xlog module#
This module contains functions to retrieve information about xlog files
- barman.xlog.DEFAULT_XLOG_SEG_SIZE = 16777216#
XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2 and larger than XLOG_BLCKSZ (preferably, a great deal larger than XLOG_BLCKSZ).
- class barman.xlog.HistoryFileData(tli, parent_tli, switchpoint, reason)#
Bases:
tuple
This namedtuple is a container for the information contained inside history files
- _asdict()#
Return a new dict which maps field names to their values.
- _field_defaults = {}#
- _fields = ('tli', 'parent_tli', 'switchpoint', 'reason')#
- classmethod _make(iterable)#
Make a new HistoryFileData object from a sequence or iterable
- _replace(**kwds)#
Return a new HistoryFileData object replacing specified fields with new values
- parent_tli#
Alias for field number 1
- reason#
Alias for field number 3
- switchpoint#
Alias for field number 2
- tli#
Alias for field number 0
- barman.xlog._validate_timeline(timeline)View on GitHub#
Check that timeline is a valid timeline value.
- barman.xlog._wal_archive_filter_fun(timeline, wal)View on GitHub#
- barman.xlog.check_archive_usable(existing_wals, timeline=None)View on GitHub#
Carry out pre-flight checks on the existing content of a WAL archive to determine if it is safe to archive WALs from the supplied timeline.
- barman.xlog.decode_hash_dir(hash_dir)View on GitHub#
Get the timeline and log from a hash dir prefix.
- Parameters:
hash_dir (str) – A string representing the prefix used when determining the folder or object key prefix under which Barman will store a given WAL segment. This prefix is composed of the timeline and the higher 32-bit number of the WAL segment.
- Return type:
List[int]
- Returns:
A list of two elements where the first item is the timeline and the second is the higher 32-bit number of the WAL segment.
- barman.xlog.decode_history_file(wal_info, comp_manager)View on GitHub#
Read an history file and parse its contents.
Each line in the file represents a timeline switch, each field is separated by tab, empty lines are ignored and lines starting with ‘#’ are comments.
Each line is composed by three fields: parentTLI, switchpoint and reason. “parentTLI” is the ID of the parent timeline. “switchpoint” is the WAL position where the switch happened “reason” is an human-readable explanation of why the timeline was changed
- The method requires a CompressionManager object to handle the eventual
compression of the history file.
- Parameters:
wal_info (barman.infofile.WalFileInfo) – history file obj
comp_manager – compression manager used in case of history file compression
- Return List[HistoryFileData]:
information from the history file
- barman.xlog.decode_segment_name(path)View on GitHub#
Retrieve the timeline, log ID and segment ID from the name of a xlog segment
It can handle either a full file path or a simple file name.
- barman.xlog.diff_lsn(lsn_string1, lsn_string2)View on GitHub#
Calculate the difference in bytes between two string XLOG location, formatted as %X/%X
Tis function is a Python implementation of the
pg_xlog_location_diff(str, str)
PostgreSQL function.
- barman.xlog.encode_history_file_name(tli)View on GitHub#
Build the history file name based on timeline
- Return str:
history file name
- barman.xlog.encode_segment_name(tli, log, seg)View on GitHub#
Build the xlog segment name based on timeline, log ID and segment ID
- barman.xlog.format_lsn(lsn)View on GitHub#
Transform a numeric XLOG location, in the corresponding %X/%X string representation
- barman.xlog.generate_segment_names(begin, end=None, version=None, xlog_segment_size=None)View on GitHub#
Generate a sequence of XLOG segments starting from
begin
If anend
segment is provided the sequence will terminate after returning it, otherwise the sequence will never terminate.If the XLOG segment size is known, this generator is precise, switching to the next file when required.
It the XLOG segment size is unknown, this generator will generate all the possible XLOG file names. The size of an XLOG segment can be every power of 2 between the XLOG block size (8Kib) and the size of a log segment (4Gib)
- barman.xlog.hash_dir(path)View on GitHub#
Get the directory where the xlog segment will be stored
It can handle either a full file path or a simple file name.
- Parameters:
path (str|unicode) – xlog file name
- Return str:
directory name
- barman.xlog.is_any_xlog_file(path)View on GitHub#
Return True if the xlog is either a WAL segment, a .backup file or a .history file, False otherwise.
It supports either a full file path or a simple file name.
- barman.xlog.is_backup_file(path)View on GitHub#
Return True if the xlog is a .backup file, False otherwise
It supports either a full file path or a simple file name.
- barman.xlog.is_history_file(path)View on GitHub#
Return True if the xlog is a .history file, False otherwise
It supports either a full file path or a simple file name.
- barman.xlog.is_partial_file(path)View on GitHub#
Return True if the xlog is a .partial file, False otherwise
It supports either a full file path or a simple file name.
- barman.xlog.is_wal_file(path)View on GitHub#
Return True if the xlog is a regular xlog file, False otherwise
It supports either a full file path or a simple file name.
- barman.xlog.location_from_xlogfile_name_offset(file_name, file_offset, xlog_segment_size)View on GitHub#
Convert file_name and file_offset to a transaction log location.
This is the inverted function of PostgreSQL’s pg_xlogfile_name_offset function.
- barman.xlog.location_to_xlogfile_name_offset(location, timeline, xlog_segment_size)View on GitHub#
Convert transaction log location string to file_name and file_offset
This is a reimplementation of pg_xlogfile_name_offset PostgreSQL function
This method returns a dictionary containing the following data:
file_name
file_offset
- barman.xlog.parse_lsn(lsn_string)View on GitHub#
Transform a string XLOG location, formatted as %X/%X, in the corresponding numeric representation
- barman.xlog.xlog_segment_mask(xlog_segment_size)View on GitHub#
Given that WAL files are named using the following pattern:
<timeline_number><xlog_file_number><xlog_segment_number>
this is the bitmask of segment part of an XLOG file. See the documentation of xlog_segments_per_file for a commentary on the definition of XLOG file.
- Parameters:
xlog_segment_size (int) – The XLOG segment size in bytes
- Return int:
The size of an XLOG file
- barman.xlog.xlog_segments_per_file(xlog_segment_size)View on GitHub#
Given that WAL files are named using the following pattern:
<timeline_number><xlog_file_number><xlog_segment_number>
this is the number of XLOG segments in an XLOG file. By XLOG file we don’t mean an actual file on the filesystem, but the definition used in the PostgreSQL sources: meaning a set of files containing the same file number.
- Parameters:
xlog_segment_size (int) – The XLOG segment size in bytes
- Return int:
The number of segments in an XLOG file