Skip to content

feat(bootstrap): support additionalArgs for pg_basebackup bootstrap - #11595

Merged
armru merged 6 commits into
cloudnative-pg:mainfrom
leonardoce:pgbasebackup-addargs
Oct 13, 2026
Merged

armru merged 6 commits into
cloudnative-pg:mainfrom
leonardoce:pgbasebackup-addargs

Conversation

@leonardoce

@leonardoce leonardoce commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Add an optional additionalArgs list under spec.bootstrap.pg_basebackup.

The arguments are appended to the pg_basebackup command built by the operator, so advanced users can tune the copy of a large data directory without patching generated objects:

spec:
  bootstrap:
    pg_basebackup:
      source: cluster-example
      additionalArgs:
        - --max-rate=50M
        - --checkpoint=fast
        - --sync-method=syncfs

Closes #11622
Closes #11379

@leonardoce
leonardoce requested a review from a team as a code owner October 1, 2026 12:15
@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 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

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 leonardoce added no-issue 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 1, 2026
@gbartolini gbartolini changed the title feat(bootstrap): support additionalArgs for pg_basebackup bootstrap feat(bootstrap): support additionalArgs for pg_basebackup bootstrap Oct 8, 2026
@gbartolini
gbartolini force-pushed the pgbasebackup-addargs branch from 82430b8 to 700b975 Compare October 8, 2026 16:53
@gbartolini gbartolini removed no-issue do not backport This PR must not be backported - it will be in the next minor release labels Oct 8, 2026
@gbartolini

gbartolini commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

I have tested this by deploying cluster-example then the cluster-replica-tls from docs/src/samples folder. I have modified the latter as follows:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-replica-tls
spec:
  instances: 3

  bootstrap:
    pg_basebackup:
      source: cluster-example
      additionalArgs:
        - --max-rate=50M
        - --checkpoint=fast
        - --sync-method=syncfs

  replica:
    primary: cluster-example
    source: cluster-example

  storage:
    size: 1Gi

  externalClusters:
  - name: cluster-example
    connectionParameters:
      host: cluster-example-rw.default.svc
      user: streaming_replica
      sslmode: verify-full
      dbname: postgres
    sslKey:
      name: cluster-example-replication
      key: tls.key
    sslCert:
      name: cluster-example-replication
      key: tls.crt
    sslRootCert:
      name: cluster-example-ca
      key: ca.crt

Then checked the logs, and verified this line:

{
  "level": "info",
  "ts": "2026-10-08T17:35:55.643476177Z",
  "msg": "Executing pg_basebackup",
  "logging_pod": "cluster-replica-tls-1",
  "command": "pg_basebackup",
  "options": [
    "-D",
    "/var/lib/postgresql/data/pgdata",
    "-v",
    "-w",
    "-d",
    "dbname='postgres' host='cluster-example-rw.default.svc' sslcert='/controller/external/cluster-example/cluster-example-replication_tls.crt' sslkey='/controller/external/cluster-example/cluster-example-replication_tls.key' sslmode='verify-full' sslrootcert='/controller/external/cluster-example/cluster-example-ca_ca.crt' user='streaming_replica' options='-c wal_sender_timeout=0s'",
    "--max-rate=50M",
    "--checkpoint=fast",
    "--sync-method=syncfs"
  ]
}

@gbartolini gbartolini added do not backport This PR must not be backported - it will be in the next minor release and removed backport-requested ◀️ This pull request should be backported to all supported releases labels Oct 12, 2026
@armru
armru force-pushed the pgbasebackup-addargs branch from 700646b to a5870e5 Compare October 12, 2026 15:17
@armru
armru force-pushed the pgbasebackup-addargs branch from a5870e5 to f08552e Compare October 12, 2026 15:27
@armru

armru commented Oct 12, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@armru

armru commented Oct 13, 2026

Copy link
Copy Markdown
Member

/ok-to-merge

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 13, 2026
leonardoce and others added 4 commits October 13, 2026 11:29
Users can now set spec.bootstrap.pg_basebackup.additionalArgs to pass
custom flags to the pg_basebackup invocation, e.g. --checkpoint=fast or
--compress=lz4.

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

Rework the additionalArgs section of the bootstrap page with a more
meaningful example (--max-rate, --checkpoint, --sync-method), explain the
arguments, and state that the option is advanced, untested in combination
and bootstrap-only.

Log the effective `pg_basebackup` options before executing the command.

Signed-off-by: Gabriele Bartolini <[email protected]>
Reject, in `spec.bootstrap.pg_basebackup.additionalArgs`, the `pg_basebackup`
options the operator relies on: target and format (-D, -F, -R, -X, -t,
--waldir), connection (-d, -h, -p, -U, -w, -W), tablespace mapping (-T),
and --help/--version. Grouped short options and abbreviated long options
are detected too, as getopt_long accepts them.

Update the API documentation to reflect that only these options are
validated.

Signed-off-by: Gabriele Bartolini <[email protected]>
forbiddenPgBaseBackupOption returned the option, the reason and a found
flag, which the only caller immediately joined into one message. Build the
message in the helper and return an empty string for an accepted argument.

Signed-off-by: Armando Ruocco <[email protected]>
armru added 2 commits October 13, 2026 11:29
…command

Check that the arguments set in additionalArgs reach the pgbasebackup
command and survive the shell quoting round trip, including a value with
spaces and quotes.

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

With --create-slot, pg_basebackup creates a permanent physical replication
slot on the source instead of a temporary one. The new cluster never uses
it, as neither the new primary nor a replica cluster configures that slot,
so the source keeps retaining WAL until its disk fills up. Reject -C and
--create-slot in additionalArgs, and point the API comment to the
documented list of rejected options instead of repeating an incomplete one.

Signed-off-by: Armando Ruocco <[email protected]>
@armru
armru force-pushed the pgbasebackup-addargs branch from ce783d7 to 16db580 Compare October 13, 2026 09:29
@armru
armru merged commit 71b37de into cloudnative-pg:main Oct 13, 2026
cnpg-bot pushed a commit to cloudnative-pg/api that referenced this pull request Oct 13, 2026
…ap (cloudnative-pg/cloudnative-pg#11595)

Add an optional `additionalArgs` list under
`spec.bootstrap.pg_basebackup`.

The arguments are appended to the `pg_basebackup` command built by the
operator, so advanced users can tune the copy of a large data directory
without patching generated objects:

```yaml
spec:
  bootstrap:
    pg_basebackup:
      source: cluster-example
      additionalArgs:
        - --max-rate=50M
        - --checkpoint=fast
        - --sync-method=syncfs
```

Closes cloudnative-pg/cloudnative-pg#11622
Closes cloudnative-pg/cloudnative-pg#11379

---------

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

(cherry picked from commit cloudnative-pg/cloudnative-pg@71b37de)
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]: Add additionalArgs to the pg_basebackup bootstrap [Feature]: Allow configuring pg_basebackup --sync-method=syncfs

4 participants