Skip to content

fix(pg_upgrade_scripts): mpg-1579 fix ship logs - #2739

Merged
jpargudo merged 8 commits into
developfrom
jpargudo/mpg-1579-fix-ship-logs
Nov 27, 2026
Merged

jpargudo merged 8 commits into
developfrom
jpargudo/mpg-1579-fix-ship-logs

Conversation

@jpargudo

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

  1. Use the ANON key generated on the new box (TARGET) of an upgrade on the SOURCE box, so we're 100% sure the anonymous key is up-to-date when it come to ship logs on error, upon an upgrade.

  2. Handles pg_upgrade outputs fully, and ship thems to the reporting project. Only ship the log files of the latest attempt, placing older logs into another folder in /var/log.

  3. Added usage of lsofand fuser in the prepare.sh if they are present: they will be used to detect what's going on when we can't umount /data. AMIs don't ship them actually, but they might in the future. The previous listing is of course still there (user, pid and command actually on /data/)

What is the current behavior?

  1. If the SOURCE box is "old enough", there are chances that this anonymous key isn't valid anymore. As a consequence, when a log needs to be shipped because the upgrade process is failing on the TARGET box (curl / post on the error_logs project), it is not shipped. This is mostly annoying when it's the initiate.sh script that fails, because it is runs on the TARGET box, and if the upgrade fails, everything falls back onto the previous version of project in the SOURCE box, hence, the log from the initiate.sh script is lost, because the TARGET is destroyed at the very end of this "rollback" process.

  2. pg_upgrade logs aren't logged and then, not shipped. This is annoying to debug failed pg_upgrade attempts: an SSH on the box is then mandatory.

  3. We only list which user/pid is on /data/ as current working directory, but an user/process could actually write on it or use a file in there preventing the umount.

What is the new behavior?

  1. To ensure that in such case the log is shipped properly, with a freshly created ANON Key of the error_logs project, we simply pass over that key in the prepare.sh part of the upgrade, directly copying it to the /data/ that will be later mounted on the SOURCE. This is the same mechanism we do already for the pgsodium key. This way, if (only) an anonymous key exists, then, we backup it (.bkp extension locally) and put in place that fresh anonymous key instead. Also, in the beginning of the initiate.sh script we do the same we already did in the prepare.sh, i.e hardening a bit the creation of the LOG_FILE, don't append to it anymore (previous attempts from the past where already logged anyways).

  2. We ship every log output of pg_upgrade and eventually the .txt generated on special checks (see PostgreSQL's source at pg_upgrade/check.c). If previous attemps are detected, we don't add those in the same directory, to not ship everything. Instead we move the previous attempts in a /previous/ post-fixed directory name in /var/log.

  3. lsof and fuser will be used if they are present on the system. This is to enable better logs in the future when those binaries might be present. If they aren't, they aren't used, and the list of user+pid currently in /data as their working directory is still listed and logged.

@jpargudo
jpargudo requested a review from a team as a code owner November 26, 2026 07:53
@jpargudo jpargudo changed the title Jpargudo/mpg 1579 fix ship logs fix(pg_upgrade_scripts): mpg-1579 fix ship logs Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Package version diff

Compares built package versions in legacyPackages between this PR and the tip of the base branch, per system.

aarch64-linux: Closure size: 372 -> 372 (2 paths added, 2 paths removed, delta +0, disk usage +7.7KiB).
<<< /nix/store/73bw5w6yyihmdksv23xh4ygrwlyf73kq-build-ami
>>> /nix/store/pqn16al8kqhqvny77rg5m67b49v1pmlj-build-ami
No version or selection state changes.
Closure size: 98 -> 98 (2 paths added, 2 paths removed, delta +0, disk usage +7.7KiB).
<<< /nix/store/6j7kss7ggd0mkrf5ya2r0c6dmnlg5j7n-build-qemu-image
>>> /nix/store/qh43xmdmsvb7x775yarzp7274wb0d039-build-qemu-image
No version or selection state changes.
Closure size: 372 -> 372 (2 paths added, 2 paths removed, delta +0, disk usage +7.7KiB).
x86_64-linux: Closure size: 370 -> 370 (2 paths added, 2 paths removed, delta +0, disk usage +7.7KiB).
<<< /nix/store/dja2i7gr8klpqpvsaw9jj7qfvv7siq0f-build-ami
>>> /nix/store/y3jgbrdckiyqysj8vbx7ipf80d6vf8x6-build-ami
No version or selection state changes.
Closure size: 99 -> 99 (2 paths added, 2 paths removed, delta +0, disk usage +7.7KiB).
<<< /nix/store/6ky8gi88dz0w4iih26n7fy749vb9ygv5-build-qemu-image
>>> /nix/store/h0a538yy2vfk7x1gymjh01qakh1wchzq-build-qemu-image
No version or selection state changes.
Closure size: 370 -> 370 (2 paths added, 2 paths removed, delta +0, disk usage +7.7KiB).

@valigula valigula left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review findings (unverified; please sanity-check before acting).

@valigula valigula left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jpargudo
jpargudo added this pull request to the merge queue Nov 27, 2026
Merged via the queue into develop with commit 74cea37 Nov 27, 2026
63 checks passed
@jpargudo
jpargudo deleted the jpargudo/mpg-1579-fix-ship-logs branch November 27, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants