Skip to content

[Feature]: Support tablespace mapping in the pg_basebackup bootstrap #11621

Description

@gbartolini

Is there an existing issue already for this feature request/idea?

  • I have searched for an existing issue, and could not find anything. I believe this is a new feature request to be evaluated.

What problem is this feature going to solve? Why should it be added?

The pg_basebackup bootstrap currently requires the source and the target to have the same tablespaces ("Requirements" in the Bootstrap documentation). In CloudNativePG, tablespaces live under /var/lib/postgresql/tablespaces/<name>/data, so a source that uses any other location cannot be cloned, even though pg_basebackup supports relocation natively through --tablespace-mapping (-T olddir=newdir, plain format only).

This blocks the physical migration of existing PostgreSQL instances that use tablespaces (VMs, other operators) and the cloning of CloudNativePG clusters whose tablespaces were created at different paths.

Describe the solution you'd like

A typed field under bootstrap.pg_basebackup that maps each tablespace declared in spec.tablespaces to its location on the source. The operator derives the target path, so the internal volume layout never appears in the manifest, and passes one -T source=target per entry to pg_basebackup.

spec:
  tablespaces:
  - name: fast
    storage:
      size: 1Gi
  bootstrap:
    pg_basebackup:
      source: cluster-example
      tablespaceMapping:
      - name: fast
        sourceLocation: /data/pg/fast

Suggested behaviour:

  • A list of named objects (+listType=map, +listMapKey=name), so names are unique and per-tablespace options can be added later without a breaking change.
  • Validation in the webhook: every name exists in spec.tablespaces; each sourceLocation is an absolute path, free of =, and unique.
  • The mapping applies to bootstrap only. Replica joins from a CloudNativePG primary share the clone code path but must not use it.
  • A source tablespace without a mapping fails with a clear message and status condition, instead of pg_basebackup writing to the source path inside the pod.
  • Documentation: replace "same tablespaces" in the requirements with the mapping, and add a warning that no CREATE TABLESPACE may run on the source between the start of the base backup and promotion. WAL replay carries the source path unmodified (PostgreSQL docs, warm standby, "Planning"), so replay would fail on the target. This applies to replica clusters for as long as they follow the source.
  • Tests covering the generated arguments and the validation.

Describe alternatives you've considered

  • A raw additionalArgs passthrough: rejected, for the same reasons initdb.options is deprecated (flags such as -D or -F break the operator).
  • Relocating tablespaces on the source before cloning: possible, but intrusive and often needs downtime.
  • Logical import: still the recommended approach where possible, but it works per database and does not fit every scenario.

Additional context

  • pg_basebackup documentation: --tablespace-mapping.
  • Open questions: the field name (tablespaceMapping mirrors --tablespace-mapping, while sourceLocation makes the direction explicit, as the CloudNativePG name is the key and not the old path); whether the recovery bootstrap should reuse the same type; a follow-up to surface a WAL replay failure on a tablespace record as a distinct status condition.

Backport?

No

Are you willing to actively contribute to this feature?

Yes

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added this to the 1.31.0 milestone on Oct 6, 2026
  2. self-assigned this
    on Oct 6, 2026
  3. added
    enhancement 🪄
    on Oct 6, 2026
  4. added a commit that references this issue on Oct 15, 2026
    89e5adb
  5. added a commit that references this issue on Oct 15, 2026
    5291afa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement 🪄

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions