Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept fix for barman backup --wait on pg17 #1044

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion barman/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from barman.postgres_plumbing import function_name_map
from barman.remote_status import RemoteStatusMixin
from barman.utils import force_str, simplify_version, with_metaclass
from barman.xlog import previous_segment_name

try:
from queue import Empty
Expand Down Expand Up @@ -739,7 +740,14 @@ def current_xlog_info(self):
"CURRENT_TIMESTAMP AS timestamp "
"FROM {pg_current_wal_lsn}() AS location".format(**self.name_map)
)
return cur.fetchone()
result = cur.fetchone()
# pg_walfile_name_offset() in Postgres 17 returns the current segment
# if on a segment boundary so return the previous segment name in that case.
if self.server_version >= 170000 and result["file_offset"] == 00000000:
result["file_name"] = previous_segment_name(
result["file_name"], self.xlog_segment_size
)
return result
else:
cur.execute(
"SELECT location, "
Expand Down
20 changes: 20 additions & 0 deletions barman/xlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,26 @@ def generate_segment_names(begin, end=None, version=None, xlog_segment_size=None
cur_log += 1


def previous_segment_name(segment, xlog_segment_size):
"""
Get the previous XLOG segment name

:param str segment: segment name
:param int xlog_segment_size: the size of a XLOG segment
:rtype: str
:raise: BadXlogSegmentName
"""
tli, log, seg = decode_segment_name(segment)
xlog_seg_per_file = xlog_segments_per_file(xlog_segment_size)
prev_log, prev_seg = log, seg
if prev_seg == 0:
prev_seg = xlog_seg_per_file
prev_log -= 1
else:
prev_seg -= 1
return encode_segment_name(tli, prev_log, prev_seg)


def hash_dir(path):
"""
Get the directory where the xlog segment will be stored
Expand Down