Skip to content

Commit

Permalink
One more occurence of making pg_wal contents disappear
Browse files Browse the repository at this point in the history
If PostgreSQL asks for a file, we need to copy it there not rename it if
it already exists.

This is the case when PG asks for a timeline to be copied over to
RECOVERYTIMELINE.
  • Loading branch information
rdunklau committed Feb 25, 2025
1 parent 5b1525e commit e926f26
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pghoard/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def get_wal_or_timeline_file(self, site: str, filename: str, filetype: str) -> N
# After reaching a recovery_target and restart of a PG server, PG wants to replay and refetch
# files from the archive starting from the latest checkpoint. We have potentially fetched these files
# already earlier. Check if we have the files already and if we do, don't go over the network to refetch
# them yet again but just rename them to the path that PG is requesting.
# them yet again but just copy them to the path that PG is requesting.
xlog_path = os.path.join(xlog_dir, filename)
exists_on_disk = os.path.exists(xlog_path)
if exists_on_disk and filename not in self.server.served_from_disk:
Expand All @@ -550,7 +550,8 @@ def get_wal_or_timeline_file(self, site: str, filename: str, filetype: str) -> N
except ValueError as e:
self.server.log.warning("Found file: %r but it was invalid: %s", xlog_path, e)
else:
self._rename(xlog_path, target_path)
if xlog_path != target_path:
shutil.copyfile(xlog_path, target_path)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
self.server.served_from_disk.append(filename)
self.server.most_recently_served_files[filetype] = {
"name": filename,
Expand Down

0 comments on commit e926f26

Please sign in to comment.