Skip to content

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

Support up to 5 RRs for XL compute and above (#29250)

Joshen Lim35ab4e8ada15
diff --git a/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx b/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
index f1b4b133636..f3c2748d326 100644
--- a/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
@@ -12,7 +12,7 @@ import {
useProjectContext,
} from 'components/layouts/ProjectLayout/ProjectContext'
import { setProjectStatus } from 'data/projects/projects-query'
-import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
+import { MAX_REPLICAS_BELOW_XL, useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useProjectAddonRemoveMutation } from 'data/subscriptions/project-addon-remove-mutation'
import { useProjectAddonUpdateMutation } from 'data/subscriptions/project-addon-update-mutation'
@@ -163,12 +163,18 @@ const ComputeInstanceSidePanel = () => {
const selectedCompute = availableOptions.find((option) => option.identifier === selectedOption)
const hasChanges =
selectedOption !== (subscriptionCompute?.variant.identifier ?? defaultInstanceSize)
- const hasReadReplicas = (databases ?? []).length > 1
-
- const blockDowngradeDueToPitr =
- pitrAddon !== undefined && ['ci_micro', 'ci_nano'].includes(selectedOption) && hasChanges
+ const numReadReplicas = (databases ?? []).filter((db) => db.identifier !== projectRef).length
+ const hasReadReplicas = numReadReplicas > 0
+
+ const isDowngradingToBelowSmall = ['ci_micro', 'ci_nano'].includes(selectedOption)
+ const blockDowngradeDueToPitr = pitrAddon !== undefined && isDowngradingToBelowSmall && hasChanges
+ const hasMoreThanTwoReplicasForXLAndAbove =
+ numReadReplicas > MAX_REPLICAS_BELOW_XL &&
+ ['ci_micro', 'ci_small', 'ci_medium', 'ci_large'].includes(selectedOption)
const blockDowngradeDueToReadReplicas =
- hasChanges && hasReadReplicas && ['ci_micro', 'ci_nano'].includes(selectedOption)
+ hasChanges &&
+ hasReadReplicas &&
+ (isDowngradingToBelowSmall || hasMoreThanTwoReplicasForXLAndAbove)
useEffect(() => {
if (visible) {
@@ -409,12 +415,14 @@ const ComputeInstanceSidePanel = () => {
<Alert_Shadcn_>
<WarningIcon />
<AlertTitle_Shadcn_>
- Unable to downgrade as project has active read replicas
+ {hasMoreThanTwoReplicasForXLAndAbove && selectedOption !== 'ci_micro'
+ ? `Unable to downgrade as project has more than ${MAX_REPLICAS_BELOW_XL} read replicas`
+ : 'Unable to downgrade as project has active read replicas'}
</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
- The minimum compute size for using read replicas is the Small Compute. You need to
- remove all read replicas before downgrading Compute as it requires at least a
- Small compute instance.
+ {hasMoreThanTwoReplicasForXLAndAbove && selectedOption !== 'ci_micro'
+ ? `You can only have up to ${MAX_REPLICAS_BELOW_XL} read replicas for compute sizes below XL, as such you will need to remove at least ${numReadReplicas - MAX_REPLICAS_BELOW_XL} read replica${numReadReplicas - MAX_REPLICAS_BELOW_XL > 1 ? 's' : ''} before downgrading your compute.`
+ : 'The minimum compute size for using read replicas is the Small Compute. You need to remove all read replicas before downgrading Compute as it requires at least a Small compute instance.'}
</AlertDescription_Shadcn_>
<AlertDescription_Shadcn_ className="mt-2">
<Button asChild type="default">
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx
index 9567a6a1821..849b869e4c0 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx
@@ -7,7 +7,11 @@ import { useParams } from 'common'
import { useEnablePhysicalBackupsMutation } from 'data/database/enable-physical-backups-mutation'
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { Region, useReadReplicaSetUpMutation } from 'data/read-replicas/replica-setup-mutation'
-import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
+import {
+ MAX_REPLICAS_ABOVE_XL,
+ MAX_REPLICAS_BELOW_XL,
+ useReadReplicasQuery,
+} from 'data/read-replicas/replicas-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
@@ -44,12 +48,24 @@ const DeployNewReplicaPanel = ({
const { ref: projectRef } = useParams()
const project = useSelectedProject()
const org = useSelectedOrganization()
- const [refetchInterval, setRefetchInterval] = useState<number | false>(false)
const { data } = useReadReplicasQuery({ projectRef })
const { data: addons, isSuccess } = useProjectAddonsQuery({ projectRef })
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: org?.slug })
+ // Opting for useState temporarily as Listbox doesn't seem to work with react-hook-form yet
+ const [defaultRegion] = Object.entries(AWS_REGIONS).find(
+ ([_, name]) => name === AWS_REGIONS_DEFAULT
+ ) ?? ['ap-southeast-1']
+ // Will be following the primary's compute size for the time being
+ const defaultCompute =
+ addons?.selected_addons.find((addon) => addon.type === 'compute_instance')?.variant
+ .identifier ?? 'ci_micro'
+
+ const [refetchInterval, setRefetchInterval] = useState<number | false>(false)
+ const [selectedRegion, setSelectedRegion] = useState<string>(defaultRegion)
+ const [selectedCompute, setSelectedCompute] = useState(defaultCompute)
+
useProjectDetailQuery(
{ ref: projectRef },
{
@@ -85,7 +101,13 @@ const DeployNewReplicaPanel = ({
(project?.dbVersion ?? '').split('supabase-postgres-')[1]?.split('.')[0]
)
- const reachedMaxReplicas = (data ?? []).filter((db) => db.identifier !== projectRef).length >= 2
+ const maxNumberOfReplicas = ['ci_micro', 'ci_small', 'ci_medium', 'ci_large'].includes(
+ selectedCompute
+ )
+ ? MAX_REPLICAS_BELOW_XL
+ : MAX_REPLICAS_ABOVE_XL
+ const reachedMaxReplicas =
+ (data ?? []).filter((db) => db.identifier !== projectRef).length >= maxNumberOfReplicas
const isFreePlan = subscription?.plan.id === 'free'
const isAWSProvider = project?.cloud_provider === 'AWS'
const isWalgEnabled = project?.is_physical_backups_enabled
@@ -105,18 +127,6 @@ const DeployNewReplicaPanel = ({
const computeAddons =
addons?.available_addons.find((addon) => addon.type === 'compute_instance')?.variants ?? []
-
- // Opting for useState temporarily as Listbox doesn't seem to work with react-hook-form yet
- const [defaultRegion] = Object.entries(AWS_REGIONS).find(
- ([_, name]) => name === AWS_REGIONS_DEFAULT
- ) ?? ['ap-southeast-1']
- // Will be following the primary's compute size for the time being
- const defaultCompute =
- addons?.selected_addons.find((addon) => addon.type === 'compute_instance')?.variant
- .identifier ?? 'ci_micro'
-
- const [selectedRegion, setSelectedRegion] = useState<string>(defaultRegion)
- const [selectedCompute, setSelectedCompute] = useState(defaultCompute)
const selectedComputeMeta = computeAddons.find((addon) => addon.identifier === selectedCompute)
const availableRegions =
@@ -153,26 +163,6 @@ const DeployNewReplicaPanel = ({
header="Deploy a new read replica"
onConfirm={() => onSubmit()}
confirmText="Deploy replica"
- // [Joshen] Refer to EnablePhysicalBackupsModal as to why this is commented out for now
- // customFooter={
- // <div className="border-t p-2 flex items-center justify-end space-x-2">
- // <Button type="default" disabled={false} onClick={onClose}>
- // Cancel
- // </Button>
- // {isMinimallyOnSmallCompute && !isWalgEnabled ? (
- // <EnablePhysicalBackupsModal selectedRegion={selectedRegion} />
- // ) : (
- // <Button
- // type="primary"
- // disabled={!canDeployReplica}
- // loading={isSettingUp}
- // onClick={onSubmit}
- // >
- // Deploy replica
- // </Button>
- // )}
- // </div>
- // }
>
<SidePanel.Content className="flex flex-col py-4 gap-y-4">
{!isAWSProvider ? (
@@ -312,12 +302,36 @@ const DeployNewReplicaPanel = ({
<Alert_Shadcn_>
<WarningIcon />
<AlertTitle_Shadcn_>
- You can only deploy up to 2 read replicas at once
+ You can only deploy up to {maxNumberOfReplicas} read replicas at once
</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
If you'd like to spin up another read replica, please drop an existing replica
first.
</AlertDescription_Shadcn_>
+ {maxNumberOfReplicas === MAX_REPLICAS_BELOW_XL && (
+ <>
+ <AlertDescription_Shadcn_>
+ <span>
+ Alternatively, you may deploy up to{' '}
+ <span className="text-foreground">{MAX_REPLICAS_ABOVE_XL}</span> replicas if
+ your project is on an XL compute or higher.
+ </span>
+ <div className="flex items-center gap-x-2 mt-3">
+ <Button asChild type="default">
+ <Link
+ href={
+ isFreePlan
+ ? `/org/${org?.slug}/billing?panel=subscriptionPlan`
+ : `/project/${projectRef}/settings/addons?panel=computeInstance`
+ }
+ >
+ Upgrade compute size
+ </Link>
+ </Button>
+ </div>
+ </AlertDescription_Shadcn_>
+ </>
+ )}
</Alert_Shadcn_>
)}
</>
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropAllReplicasConfirmationModal.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropAllReplicasConfirmationModal.tsx
index 7b2fc820ca1..8f64c09bdc5 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropAllReplicasConfirmationModal.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DropAllReplicasConfirmationModal.tsx
@@ -70,7 +70,7 @@ const DropAllReplicasConfirmationModal = ({
}}
>
<p className="text-sm">Before deleting all replicas, consider:</p>
- <ul className="text-sm text-foreground-light list-disc">
+ <ul className="text-sm text-foreground-light list-disc pl-6">
<li>Network traffic from this region may slow down</li>
</ul>
</ConfirmationModal>
diff --git a/apps/studio/data/read-replicas/replicas-query.ts b/apps/studio/data/read-replicas/replicas-query.ts
index ac819c8c633..7377a7787eb 100644
--- a/apps/studio/data/read-replicas/replicas-query.ts
+++ b/apps/studio/data/read-replicas/replicas-query.ts
@@ -6,6 +6,9 @@ import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { replicaKeys } from './keys'
+export const MAX_REPLICAS_BELOW_XL = 2
+export const MAX_REPLICAS_ABOVE_XL = 5
+
export type ReadReplicasVariables = {
projectRef?: string
}