Skip to content

Snapshot restore fails when pgsql_tmp* directories exist in PGDATA #10398

Closed

Description

@mnencia

During volume snapshot restore, the PGDATA cleanup step fails with "directory not empty" when non-empty directories matching pgsql_tmp* exist in the data directory.

This happens because RemoveRestoreExcludedFiles (from the machinery library) uses os.Remove to delete paths matched by the pgsql_tmp* glob pattern, which only works for files and empty directories. Extensions loaded via shared_preload_libraries (e.g. vchord) can create directories like pgsql_tmp_vchord_sampling/ in PGDATA during recovery, and the standard PostgreSQL pgsql_tmp/ directory may also contain temporary files.

Example error:

"msg":"restore error","error":"error while cleaning up the recovered PGDATA: remove /var/lib/postgresql/data/pgdata/pgsql_tmp_vchord_sampling: directory not empty"

Per PostgreSQL documentation, all pgsql_tmp* paths are ephemeral runtime artifacts that are excluded from pg_basebackup and cleaned up automatically on startup. They should be removed unconditionally during restore cleanup, regardless of whether they are files or directories.

The fix needs to go in the machinery repository: cloudnative-pg/machinery#217

Activity

  1. added a commit that references this issue on Apr 17, 2026
    f19631d
  2. added 3 commits that reference this issue on Apr 17, 2026
    a742a35
    1784694
    0a3a744
  3. added a commit that references this issue on Apr 17, 2026
    1342d5b
  4. added
    bug 🐛Something isn't working
    and removed on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions