Skip to content

feat(bootstrap): support tablespaceMapping for pg_basebackup - #11649

Merged
mnencia merged 10 commits into
cloudnative-pg:mainfrom
leonardoce:tbls-mapping
Oct 15, 2026
Merged

mnencia merged 10 commits into
cloudnative-pg:mainfrom
leonardoce:tbls-mapping

Conversation

@leonardoce

@leonardoce leonardoce commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Sources that do not follow the CloudNativePG tablespace layout could not be cloned with pg_basebackup. Add spec.bootstrap.pg_basebackup.tablespaceMapping to map each tablespace declared in spec.tablespaces to its location in the source instance. The operator passes one --tablespace-mapping per entry to pg_basebackup for the initial clone. Replica joins do not use it.

Closes #11621


Add to the release notes:

- Added `spec.bootstrap.pg_basebackup.tablespaceMapping` to clone a source instance whose tablespaces are not in the CloudNativePG location, by mapping each tablespace declared in `spec.tablespaces` to its source path.

@leonardoce
leonardoce requested a review from a team as a code owner October 13, 2026 08:18
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Oct 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@leonardoce

Copy link
Copy Markdown
Contributor Author

This is based on #11595 and requires it to be merged.

Source tablespaces are not checked before pg_basebackup. The tablespace list isn't available over the replication connection pg_basebackup uses, so a check would need a second, regular SQL connection to the source. That would be a new requirement, because a REPLICATION LOGIN role accepted for replication in pg_hba.conf often can't open regular connections.

The webhook covers part of the gap. It rejects invalid mappings (unknown or duplicate names, relative or duplicate sourceLocation, or one containing =). It also warns about tablespaces declared in spec.tablespaces without a mapping, since that's only valid if the source uses the CloudNativePG location. It can't detect source tablespaces that aren't declared at all. The docs describe this limitation.

@armru

armru commented Oct 14, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 14, 2026
@armru
armru force-pushed the tbls-mapping branch 2 times, most recently from d9ed2f8 to a7c1f87 Compare October 14, 2026 13:08
leonardoce and others added 5 commits October 15, 2026 11:21
Users can now map each tablespace declared in spec.tablespaces to its
location in the source instance when bootstrapping from a live cluster.
Keys must be a subset of the declared tablespaces.

Signed-off-by: Leonardo Cecchi <[email protected]>
…ping

pg_basebackup relocates tablespaces by path, while the operator reconciles
them by name, so a tablespace declared under a different name than in the
source would be created again on a directory that is already in use. The
sample now uses a source path that does not look like the CloudNativePG
layout, which ends in /data.

Signed-off-by: Armando Ruocco <[email protected]>
The source instance gets a tablespace outside the CloudNativePG layout,
and the target maps it to its own volume. Every instance of the target,
including the replica that joins the new primary, must find the tablespace
in the CloudNativePG location with the data of the source.

Signed-off-by: Armando Ruocco <[email protected]>
…them

pg_basebackup canonicalizes the old directory of a tablespace mapping
before matching it, so two entries such as /data/ts and /data/ts/ refer
to the same tablespace. The webhook compared them as plain strings and
accepted both.

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
@gbartolini gbartolini changed the title feat(bootstrap): support tablespaceMapping for pg_basebackup bootstrap feat(bootstrap): support tablespaceMapping for pg_basebackup Oct 15, 2026
@mnencia mnencia added release-1.30 backport-requested ◀️ This pull request should be backported to all supported releases and removed backport-requested ◀️ This pull request should be backported to all supported releases labels Oct 15, 2026
@mnencia mnencia added do not backport This PR must not be backported - it will be in the next minor release and removed release-1.28 release-1.30 labels Oct 15, 2026
It fired on every create and update of a pg_basebackup cluster with
tablespaces and no mapping, including valid clones from a CloudNativePG
source, and the webhook cannot tell the two cases apart. The docs warning
stays.

Signed-off-by: Marco Nenciarini <[email protected]>
Drop the checks the CRD already enforces (unique names, non-empty values)
and the test that bypassed it. The job test now uses literal paths, adds a
path with a space and the additional arguments, and parses the result.

Signed-off-by: Marco Nenciarini <[email protected]>
pg_basebackup uses a backslash to escape the equal sign in a tablespace
mapping, so a location ending in one makes it fail to parse the mapping.

Signed-off-by: Marco Nenciarini <[email protected]>
Say that the operator does not check the tablespaces of the source and
when an unmapped one fails, add the missing periods to the API comments,
shorten the webhook comment, and explain the e2e source path.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia

mnencia commented Oct 15, 2026

Copy link
Copy Markdown
Member

/test ft=recovery tl=1 d=push

@github-actions

Copy link
Copy Markdown
Contributor

@mnencia
mnencia merged commit 89e5adb into cloudnative-pg:main Oct 15, 2026
cnpg-bot pushed a commit to cloudnative-pg/api that referenced this pull request Oct 15, 2026
…udnative-pg/cloudnative-pg#11649)

Sources that do not follow the CloudNativePG tablespace layout could not
be cloned with `pg_basebackup`. Add
`spec.bootstrap.pg_basebackup.tablespaceMapping` to map each tablespace
declared in `spec.tablespaces` to its location in the source instance.
The operator passes one `--tablespace-mapping` per entry to
`pg_basebackup` for the initial clone. Replica joins do not use it.

Closes cloudnative-pg/cloudnative-pg#11621

Signed-off-by: Leonardo Cecchi <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>

(cherry picked from commit cloudnative-pg/cloudnative-pg@89e5adb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not backport This PR must not be backported - it will be in the next minor release ok to merge 👌 This PR can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support tablespace mapping in the pg_basebackup bootstrap

5 participants