Skip to content

cp -l -r causes "Invalid cross-device link" failure when using tablespaces on separate Docker volumes #210

@Bidj

Description

@Bidj

Description
A recent change replaced cp -r with cp -l -r to move the new database files into the active directory (in order to save time and disk space), but it breaks upgrades for databases that use tablespaces mounted on a separate Docker volume. Just tried it and had a lot of _Invalid cross-device link errors.

cp: cannot create hard link '/var/lib/postgresql/data/pg_tblspc/16388/PG_17_202406281/16391/38891195' to '/var/lib/postgresql/data/new/pg_tblspc/16388/PG_17_202406281/16391/38891195': Invalid cross-device link cp: cannot create hard link '/var/lib/postgresql/data/pg_tblspc/16388/PG_17_202406281/16391/38891196' to '/var/lib/postgresql/data/new/pg_tblspc/16388/PG_17_202406281/16391/38891196': Invalid cross-device link

Environment
Docker volumes:
Volume 1 mounted at /var/lib/postgresql/data (Primary PGDATA)
Volume 2 mounted at /data/tablespace (Dedicated tablespace volume)
Setup: PostgreSQL has a tablespace created at /data/tablespace. In PGDATA/pg_tblspc/, there is a symlink pointing to this mount.

Example
docker run --rm --name "pgauto" -it
--mount type=bind,source="/path/to/local/postgres-data",target=/var/lib/postgresql/data
--mount type=bind,source="/path/to/local/tablespace-data",target=/data/tablespace
-e POSTGRES_PASSWORD=password
-e PGAUTO_ONESHOT=yes
pgautoupgrade/pgautoupgrade:17-debian

I don't know if the best solution is to revert the change, exclude tablespaces (from what I understand, the files inside the tablespace directory were already upgraded in place by pg_upgrade and only the symlinks themselves need to be moved/created in the root PGDATA, but I am out of my depth here) or try to detect this particular situation and choose to apply -l dynamically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions