Skip to content

feat: add option to skip policies during restore (#520)

Artyom Kartasov requested to merge 520-skip-policies into master

Description

Add option to skip policies during restore. This is needed to mitigate pg_restore errors like this one:

policy "cron_job_policy" for table "job" already exists

Unfortunately, as of now (Postgres 15), pg_restore doesn't have a flag for this:

% pg_restore --help | grep '\-\-no\-'
  -O, --no-owner               skip restoration of object ownership
  -x, --no-privileges          skip restoration of access privileges (grant/revoke)
  --no-comments                do not restore comments
  --no-data-for-failed-tables  do not restore data of tables that could not be
  --no-publications            do not restore publications
  --no-security-labels         do not restore security labels
  --no-subscriptions           do not restore subscriptions
  --no-table-access-method     do not restore table access methods
  --no-tablespaces             do not restore tablespace assignments
  -w, --no-password        never prompt for password

Therefore, it was decided to implement a work-around, using pg_restore's -l / -L:

pg_restore \
  -h 127.0.0.1 -p 6000 --username test --dbname postgres \
  --jobs 4 \
  --verbose \
  --no-tablespaces \
  --no-privileges \
  --no-owner \
  --exit-on-error \
  -L <(pg_restore -l /path/to/dump  | grep -v POLICY) \
  /path/to/dump

And extend DBLab configuration with an additional flag, skipPolicies in logicalRestore. By default it's on to match the state of other flags (that pg_restore supports natively): --no-owner, --no-privileges, etc.

Related issue

#520 (closed)

Examples

retrieval:
  spec:
    logicalRestore:
      options:
        # ...
        # Option to skip policies during restore.
        skipPolicies: false

Checklist

  • MR description has been reviewed
  • MR changes are functionally tested
  • MR does NOT have API/CLI changes OR there are API/CLI changes and they have been reviewed & DOCS ARE ADJUSTED (reference doc, etc)
  • MR does NOT have UI changes OR there are UI changes and they have been reviewed & UX IS REVIEWED

Closes #520 (closed)

Edited by Nikolay Samokhvalov

Merge request reports