Repository navigation
Description
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/fastSuggested 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
nameexists inspec.tablespaces; eachsourceLocationis 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_basebackupwriting to the source path inside the pod. - Documentation: replace "same tablespaces" in the requirements with the mapping, and add a warning that no
CREATE TABLESPACEmay 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
additionalArgspassthrough: rejected, for the same reasonsinitdb.optionsis deprecated (flags such as-Dor-Fbreak 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_basebackupdocumentation:--tablespace-mapping.- Open questions: the field name (
tablespaceMappingmirrors--tablespace-mapping, whilesourceLocationmakes the direction explicit, as the CloudNativePG name is the key and not the old path); whether therecoverybootstrap 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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(bootstrap): support `tablespaceMapping` for `pg_basebackup` (#11649
feat(bootstrap): support `tablespaceMapping` for `pg_basebackup` (clo…