Skip to content

[POSTGRESQL] az postgres flexible-server restore: Add --sku-name and --tier arguments to allow changing compute during point-in-time restore - #33992

Open
Gabriel Lobo (thegabrielobo) wants to merge 1 commit into
Azure:devfrom
thegabrielobo:pg-flex-restore-sku
Open

Conversation

@thegabrielobo

@thegabrielobo Gabriel Lobo (thegabrielobo) commented Aug 26, 2026

Copy link
Copy Markdown

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests
⚠️ None ️✔️ 130/130
⚠️AzureCLI-BreakingChangeTest
⚠️postgresql
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd postgres flexible-server restore cmd postgres flexible-server restore added parameter sku_name
⚠️ 1006 - ParaAdd postgres flexible-server restore cmd postgres flexible-server restore added parameter tier

Related command
az postgres flexible-server restore

Description
Point-in-time restore previously always inherited the source server's compute SKU, so there was no way to resize a server during a restore. This adds --sku-name and --tier to az postgres flexible-server restore, matching capability already available on az mysql flexible-server restore.

Behavior:

Arguments supplied Result
Neither Unchanged — the restored server inherits the source server's SKU
--sku-name only Tier is inherited from the source server; the SKU is validated against that tier
--tier only The default SKU for that tier is used, and a warning is emitted
Both Both are validated against the location capability API

Downgrading below the source server's compute tier is rejected, so a GeneralPurpose or MemoryOptimized server cannot be restored down to Burstable.

Two changes beyond the plain argument addition are worth reviewer attention:

  1. pg_restore_validator now receives the resolved target tier rather than the source server's tier. Previously a Burstable source could never be restored with --storage-type PremiumV2_LRS; restoring Burstable → GeneralPurpose with SSDv2 now works, which is the point of allowing a tier change.
  2. Argument validation errors are re-raised as-is instead of being masked by the surrounding except Exception: raise ResourceNotFoundError(e). Without this, an invalid --tier surfaced as a confusing "not found" error rather than the actual validation message.

Tier ordering uses an explicit rank map rather than inferring order from the capability API's dictionary key order, which is not guaranteed stable.

Testing Guide

Restore with a different compute size, inheriting the source server's tier:

az postgres flexible-server restore --resource-group testgroup --name testservernew \
  --source-server testserver --sku-name Standard_D4s_v3

Restore with a different compute tier and size:

az postgres flexible-server restore --resource-group testgroup --name testservernew \
  --source-server testserver --tier MemoryOptimized --sku-name Standard_E2ds_v4

Restore with no compute arguments, which must behave exactly as before:

az postgres flexible-server restore --resource-group testgroup --name testservernew \
  --source-server testserver

Downgrading the tier must be rejected:

az postgres flexible-server restore --resource-group testgroup --name testservernew \
  --source-server <memory-optimized-server> --tier GeneralPurpose

Automated checks run locally:

  • azdev style postgresql — Pylint PASSED, Flake8 PASSED
  • azdev linter postgresql — no violations
  • New offline unit tests in test_postgres_flexible_restore_sku_params.py (7 tests, no network) covering argument registration and pg_restore_tier_validator upgrade / same-tier / downgrade / Burstable / unknown-tier cases
  • The existing recorded restore scenario test still passes and is unmodified

The recorded scenario test was intentionally left untouched: adding new commands to it invalidates the committed cassette (RecordMode.ONCE) and requires a live re-record, which is tracked as follow-up so the new arguments get end-to-end coverage.

History Notes

[POSTGRESQL] az postgres flexible-server restore: Add --sku-name and --tier arguments to allow changing compute during point-in-time restore

…and `--tier` arguments to allow changing compute during point-in-time restore

Point-in-time restore previously always inherited the source server's compute
SKU. Users can now select a different compute size and tier for the restored
server, matching the behavior already available for MySQL flexible servers.

- When neither argument is supplied, behavior is unchanged and the restored
  server inherits the source server's SKU.
- When only `--sku-name` is supplied, the tier is inherited from the source
  server and the SKU is validated against that tier.
- When only `--tier` is supplied, the default SKU for that tier is used and a
  warning is emitted.
- Downgrading below the source server's compute tier is rejected.

`pg_restore_validator` now receives the resolved target tier rather than the
source tier, so restoring a Burstable server to GeneralPurpose with
`--storage-type PremiumV2_LRS` is no longer incorrectly rejected.

Argument validation errors are also re-raised as-is instead of being masked as
`ResourceNotFoundError` by the surrounding exception handler.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Aug 26, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution Gabriel Lobo (@thegabrielobo)! We will review the pull request and get back to you soon.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Auto-Assign Auto assign by bot label Aug 26, 2026
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@thegabrielobo
Gabriel Lobo (thegabrielobo) marked this pull request as ready for review August 26, 2026 15:11
Copilot AI lite review requested due to automatic review settings August 26, 2026 15:11
@thegabrielobo
Gabriel Lobo (thegabrielobo) requested a review from a team as a code owner August 26, 2026 15:11
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@nasc17
nasc17 self-requested a review August 26, 2026 19:12
@yonzhan

Copy link
Copy Markdown
Collaborator

postgres


class RestoreTierValidatorTest(unittest.TestCase):

def test_upgrading_tier_is_allowed(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead add new args to restore test already in project and re-record results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. do-not-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants