Skip to content

fix(charm): recover temp tablespace after cross-revision restore#1874

Draft
marceloneppel wants to merge 2 commits into
16/edgefrom
feature/help-replication-broken-after-restore
Draft

fix(charm): recover temp tablespace after cross-revision restore#1874
marceloneppel wants to merge 2 commits into
16/edgefrom
feature/help-replication-broken-after-restore

Conversation

@marceloneppel

Copy link
Copy Markdown
Member

Issue

Restoring a backup taken on a pre-versioned-storage revision (before the 16/main
subdirectory layout) into a current revision leaves the temp tablespace at the old
non-versioned path. Install and refresh already migrate it to the versioned path, but the
restore-success path did not — so after a cross-revision restore the tablespace stayed at the
old location, nested under the charm-created versioned directory. A new replica's
pg_basebackup then streamed into that versioned directory and failed with directory "…" is not empty, and create-backup failed with pgBackRest error [070] … destination is a subdirectory of link ….

Separately, on a tmpfs reboot the temp tablespace directory is recreated without its expected
mode, so set_up_database took the rename-and-leave path (ALTER TABLESPACE temp RENAME TO temp_<timestamp>) on every reboot, accumulating leftover tablespaces — which is what produced
the nested-link state above on an affected cluster.

Solution

  • Run the existing temp-tablespace migration in _was_restore_successful, before clearing the
    restoring-backup flags, so the restored primary is on the versioned layout before any replica
    streams from it or a backup runs. The check defers (preserving the flags) until the migration
    completes.
  • Set the temp tablespace directory mode to POSTGRESQL_STORAGE_PERMISSIONS on creation in
    _ensure_storage_layout, so set_up_database's permissions_need_fix gate is not tripped on
    reboot and the rename-and-leave path is not taken.

Validated end-to-end with tox run -e unit, and by reproducing the real cross-revision restore
on a cluster: the charm now migrates the tablespace automatically on restore, and create-backup
and scale-up succeed without manual intervention.

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

A backup taken on a pre-versioned-storage revision restores the temp
tablespace at the old non-versioned path. Install and refresh already
migrate it to the versioned path, but restore did not — so after a
cross-revision restore the tablespace stayed at the old location. A new
replica's pg_basebackup then streams into the charm-created versioned
directory nested under it, hitting a non-empty target and failing, and
pgBackRest rejects the nested tablespace links with error [070].

Run the existing temp-tablespace migration in the restore-success path,
before clearing the restoring-backup flags, so the restored primary is
on the versioned layout before any replica streams from it or a backup
runs.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
On a tmpfs reboot the temp tablespace directory is recreated, and
set_up_database renames the existing temp tablespace to a timestamped
leftover (temp_<timestamp>) whenever the directory's mode differs from
the expected storage permissions. _ensure_storage_layout created the
directory without setting its mode, so the default umask left it at a
mode that never matched, triggering the rename on every reboot and
accumulating leftover tablespaces the operator has to clean up.

Set the directory mode to the expected storage permissions on creation
so the rename-and-leave path is not taken.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@github-actions github-actions Bot added the Libraries: Out of sync The charm libs used are out-of-sync label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Libraries: Out of sync The charm libs used are out-of-sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant