Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): correct gp3 IOPS validation for small disks (#45957)

Joey Freeland394ccf4e275d
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagement.schema.ts b/apps/studio/components/interfaces/DiskManagement/DiskManagement.schema.ts
index 3d9250422d8..ff1743668c9 100644
--- a/apps/studio/components/interfaces/DiskManagement/DiskManagement.schema.ts
+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagement.schema.ts
@@ -191,22 +191,14 @@ export const CreateDiskStorageSchema = ({
path: ['provisionedIOPS'],
})
} else if (provisionedIOPS > maxIopsAllowedForDiskSizeWithGp3) {
- if (totalSize >= 8) {
- const diskSizeRequiredForIopsWithGp3 =
- calculateDiskSizeRequiredForIopsWithGp3(provisionedIOPS)
+ const diskSizeRequiredForIopsWithGp3 =
+ calculateDiskSizeRequiredForIopsWithGp3(provisionedIOPS)
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: `Larger Disk size of at least ${formatNumber(diskSizeRequiredForIopsWithGp3)} GB required. Current max is ${formatNumber(maxIopsAllowedForDiskSizeWithGp3)} IOPS.`,
- path: ['provisionedIOPS'],
- })
- } else {
- ctx.addIssue({
- code: z.ZodIssueCode.custom,
- message: `Invalid IOPS value due to invalid disk size`,
- path: ['provisionedIOPS'],
- })
- }
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: `Larger Disk size of at least ${formatNumber(diskSizeRequiredForIopsWithGp3)} GB required. Current max is ${formatNumber(maxIopsAllowedForDiskSizeWithGp3)} IOPS.`,
+ path: ['provisionedIOPS'],
+ })
}
if (throughput !== undefined) {
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.ts b/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.ts
index 2ad56ab5d09..c7e44d07d1e 100644
--- a/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.ts
+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.ts
@@ -5,6 +5,7 @@ import {
calculateComputeSizeRequiredForIops,
calculateDiskSizePrice,
calculateIOPSPrice,
+ calculateMaxIopsAllowedForDiskSizeWithGp3,
calculateMaxIopsForComputeSize,
calculateThroughputPrice,
mapAddOnVariantIdToComputeSize,
@@ -66,6 +67,18 @@ describe('DiskManagement utils', () => {
})
})
+describe('calculateMaxIopsAllowedForDiskSizeWithGp3', () => {
+ // Regression: old code returned `3000 * size`, letting a 2 GB disk request 6000 IOPS
+ // which the platform rejects. The real ceiling is 500 IOPS/GB capped at 16 000.
+ test('caps a sub-6 GB disk at the 3000 IOPS floor (not 3000 × size)', () => {
+ expect(calculateMaxIopsAllowedForDiskSizeWithGp3(2)).toBe(3000)
+ })
+
+ test('caps large disks at 16 000 IOPS', () => {
+ expect(calculateMaxIopsAllowedForDiskSizeWithGp3(100)).toBe(16000)
+ })
+})
+
describe('DiskManagement.utils.ts:calculateDiskSizePrice', () => {
test('GP3 with 8GB to GP3 with 10GB for pro plan', () => {
const result = calculateDiskSizePrice({
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagement.utils.ts b/apps/studio/components/interfaces/DiskManagement/DiskManagement.utils.ts
index 2753d1f1990..3e8c6bbb5ab 100644
--- a/apps/studio/components/interfaces/DiskManagement/DiskManagement.utils.ts
+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagement.utils.ts
@@ -282,7 +282,7 @@ export function getAvailableComputeOptions(
}
export const calculateMaxIopsAllowedForDiskSizeWithGp3 = (totalSize: number) => {
- return Math.min(3000 * totalSize, 16000)
+ return Math.max(3000, Math.min(500 * totalSize, 16000))
}
export const calculateDiskSizeRequiredForIopsWithGp3 = (iops: number) => {
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx
index 0f98d64dbb9..ef82187c5e4 100644
--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx
+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx
@@ -22,7 +22,10 @@ import { Admonition } from 'ui-patterns'
import { FormFooterChangeBadge } from '../DataWarehouse/FormFooterChangeBadge'
import { CreateDiskStorageSchema, DiskStorageSchemaType } from './DiskManagement.schema'
import { DiskManagementMessage } from './DiskManagement.types'
-import { mapComputeSizeNameToAddonVariantId } from './DiskManagement.utils'
+import {
+ calculateDiskSizeRequiredForIopsWithGp3,
+ mapComputeSizeNameToAddonVariantId,
+} from './DiskManagement.utils'
import { DiskMangementRestartRequiredSection } from './DiskManagementRestartRequiredSection'
import { DiskManagementReviewAndSubmitDialog } from './DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog'
import { AutoScaleFields } from './fields/AutoScaleFields'
@@ -35,6 +38,7 @@ import { DiskCountdownRadial } from './ui/DiskCountdownRadial'
import {
DISK_LIMITS,
DiskType,
+ PLAN_DETAILS,
RESTRICTED_COMPUTE_FOR_THROUGHPUT_ON_GP3,
} from './ui/DiskManagement.constants'
import { NoticeBar } from './ui/NoticeBar'
@@ -191,6 +195,18 @@ export function DiskManagementForm() {
!isSpendCapEnabled &&
RESTRICTED_COMPUTE_FOR_THROUGHPUT_ON_GP3.includes(modifiedComputeSize)
+ const watchedTotalSize = form.watch('totalSize') ?? 0
+ const watchedStorageType = form.watch('storageType')
+ // Minimum disk size where the platform API will accept an IOPS payload (500 IOPS/GB rule).
+ const minDiskSizeForCustomIops = calculateDiskSizeRequiredForIopsWithGp3(
+ DISK_LIMITS[DiskType.GP3].minIops
+ )
+ // Suggested target when prompting a resize, sits above the floor so users
+ // aren't pinned at the minimum during the 4-hour disk-config cooldown.
+ const suggestedDiskSizeForCustomIops = PLAN_DETAILS.pro.includedDiskGB.gp3
+ const isDiskTooSmallForCustomIops =
+ watchedStorageType === 'gp3' && watchedTotalSize < minDiskSizeForCustomIops
+
const isBranch = project?.parent_project_ref !== undefined
const disableDiskSizeInput =
@@ -524,17 +540,50 @@ export function DiskManagementForm() {
)
}
/>
+ <NoticeBar
+ type="default"
+ visible={
+ isDiskTooSmallForCustomIops &&
+ !disableIopsThroughputConfig &&
+ !disableDiskInputs
+ }
+ title={`Increase disk size to adjust IOPS or throughput`}
+ description={`This disk is too small to update IOPS or throughput, since gp3 volumes are capped at 500 IOPS per GB with a 3,000 IOPS minimum. Resizing to ${suggestedDiskSizeForCustomIops} GB unlocks custom IOPS and throughput, and leaves headroom for further adjustments (disk config changes are locked for 4 hours after each resize).`}
+ actions={
+ !disableDiskSizeInput ? (
+ <Button
+ type="default"
+ onClick={() => {
+ form.setValue('totalSize', suggestedDiskSizeForCustomIops, {
+ shouldDirty: true,
+ shouldValidate: true,
+ })
+ }}
+ >
+ Increase to {suggestedDiskSizeForCustomIops} GB
+ </Button>
+ ) : undefined
+ }
+ />
<StorageTypeField
form={form}
disableInput={disableIopsThroughputConfig || disableDiskInputs}
/>
<IOPSField
form={form}
- disableInput={disableIopsThroughputConfig || disableDiskInputs}
+ disableInput={
+ disableIopsThroughputConfig ||
+ disableDiskInputs ||
+ isDiskTooSmallForCustomIops
+ }
/>
<ThroughputField
form={form}
- disableInput={disableIopsThroughputConfig || disableDiskInputs}
+ disableInput={
+ disableIopsThroughputConfig ||
+ disableDiskInputs ||
+ isDiskTooSmallForCustomIops
+ }
/>
</div>
</div>