The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
use dynamic max values in database reports (#37874)
Jordi Enric6c4d3e6c5216
diff --git a/apps/studio/data/reports/database-charts.ts b/apps/studio/data/reports/database-charts.tsindex 0efc542aedd..2f4eb36e21d 100644--- a/apps/studio/data/reports/database-charts.ts+++ b/apps/studio/data/reports/database-charts.ts@@ -3,8 +3,17 @@ import { ReportAttributes } from 'components/ui/Charts/ComposedChart.utils'import { formatBytes } from 'lib/helpers'import { Organization } from 'types'import { Project } from '../projects/project-detail-query'+import { DiskAttributesData } from '../config/disk-attributes-query'+import { MaxConnectionsData } from '../database/max-connections-query'+import { PgbouncerConfigData } from '../database/pgbouncer-config-query'-export const getReportAttributes = (org: Organization, project: Project): ReportAttributes[] => {+export const getReportAttributes = (+ org: Organization,+ project: Project,+ diskConfig?: DiskAttributesData,+ maxConnections?: MaxConnectionsData,+ poolerConfig?: PgbouncerConfigData+): ReportAttributes[] => {const computeSize = project?.infra_compute_size || 'medium'return [@@ -117,7 +126,7 @@ export const getReportAttributes = (org: Organization, project: Project): Reportattribute: 'disk_iops_max',provider: 'reference-line',label: 'Max IOPS',- value: getIOPSLimits(computeSize),+ value: diskConfig?.attributes?.iops,tooltip:'Maximum IOPS (Input/Output Operations Per Second) for your current compute size',isMaxValue: true,@@ -210,10 +219,13 @@ export const getReportAttributes = (org: Organization, project: Project): Report]}-export const getReportAttributesV2: (org: Organization, project: Project) => ReportAttributes[] = (- org,- project-) => {+export const getReportAttributesV2: (+ org: Organization,+ project: Project,+ diskConfig?: DiskAttributesData,+ maxConnections?: MaxConnectionsData,+ poolerConfig?: PgbouncerConfigData+) => ReportAttributes[] = (org, project, diskConfig, maxConnections, poolerConfig) => {const isFreePlan = org?.plan?.id === 'free'const computeSize = project?.infra_compute_size || 'medium'const isSpendCapEnabled =@@ -369,7 +381,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Repattribute: 'disk_iops_max',provider: 'reference-line',label: 'Max IOPS',- value: getIOPSLimits(computeSize),+ value: diskConfig?.attributes?.iops,tooltip:'Maximum IOPS (Input/Output Operations Per Second) for your current compute size',isMaxValue: true,@@ -463,7 +475,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Repattribute: 'max_db_connections',provider: 'reference-line',label: 'Max connections',- value: getConnectionLimits(computeSize).direct,+ value: maxConnections?.maxConnections,tooltip: 'Max available connections for your current compute size',isMaxValue: true,},@@ -495,7 +507,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Repattribute: 'pg_pooler_max_connections',provider: 'reference-line',label: 'Max pooler connections',- value: getConnectionLimits(computeSize).pooler,+ value: poolerConfig?.max_client_conn,tooltip: 'Maximum allowed pooler connections for your current compute size',isMaxValue: true,},@@ -581,8 +593,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => RepisReferenceLine: true,strokeDasharray: '4 2',label: 'Spend cap enabled',- value:- (project?.volumeSizeGb || getRecommendedDbSize(computeSize)) * 1024 * 1024 * 1024,+ value: diskConfig?.attributes?.size_gb! * 1024 * 1024 * 1024,className: '[&_line]:!stroke-yellow-800 [&_line]:!opacity-100',opacity: 1,}@@ -592,77 +603,9 @@ export const getReportAttributesV2: (org: Organization, project: Project) => RepisReferenceLine: true,label: '90% - Disk resize threshold',className: '[&_line]:!stroke-yellow-800',- value:- (project?.volumeSizeGb || getRecommendedDbSize(computeSize)) *- 1024 *- 1024 *- 1024 *- 0.9, // reaching 90% of the disk size will trigger a disk resize https://supabase.com/docs/guides/platform/database-size+ value: diskConfig?.attributes?.size_gb! * 1024 * 1024 * 1024 * 0.9,}),],},]}--// Helper function to get connection limits based on compute size-export const getConnectionLimits = (computeSize: string = 'medium') => {- const connectionLimits = {- nano: { direct: 60, pooler: 200 },- micro: { direct: 60, pooler: 200 },- small: { direct: 90, pooler: 400 },- medium: { direct: 120, pooler: 600 },- large: { direct: 160, pooler: 800 },- xlarge: { direct: 240, pooler: 1000 },- '2xlarge': { direct: 380, pooler: 1500 },- '4xlarge': { direct: 480, pooler: 3000 },- '8xlarge': { direct: 490, pooler: 6000 },- '12xlarge': { direct: 500, pooler: 9000 },- '16xlarge': { direct: 500, pooler: 12000 },- }-- return (- connectionLimits[computeSize?.toLowerCase() as keyof typeof connectionLimits] ||- connectionLimits.medium- )-}--// Helper function to get IOPS limits based on compute size-export const getIOPSLimits = (computeSize: string = 'medium') => {- const iopsLimits = {- nano: 250,- micro: 500,- small: 1000,- medium: 2000,- large: 3600,- xl: 6000,- '2xl': 12000,- '4xl': 20000,- '8xl': 40000,- '12xl': 50000,- '16xl': 80000,- }-- return iopsLimits[computeSize?.toLowerCase() as keyof typeof iopsLimits] || iopsLimits.medium-}--// Helper function to get recommended DB size based on compute size (in GB)-export const getRecommendedDbSize = (computeSize: string = 'medium') => {- const recommendedSizes = {- nano: 0.5, // 500 MB- micro: 10,- small: 50,- medium: 100,- large: 200,- xl: 500,- '2xl': 1024, // 1 TB- '4xl': 2048, // 2 TB- '8xl': 4096, // 4 TB- '12xl': 6144, // 6 TB- '16xl': 10240, // 10 TB- }-- return (- recommendedSizes[computeSize?.toLowerCase() as keyof typeof recommendedSizes] ||- recommendedSizes.medium- )-}diff --git a/apps/studio/pages/project/[ref]/reports/database.tsx b/apps/studio/pages/project/[ref]/reports/database.tsxindex dab6b263b61..6a3fd20c334 100644--- a/apps/studio/pages/project/[ref]/reports/database.tsx+++ b/apps/studio/pages/project/[ref]/reports/database.tsx@@ -27,7 +27,10 @@ import GrafanaPromoBanner from 'components/ui/GrafanaPromoBanner'import Panel from 'components/ui/Panel'import { analyticsKeys } from 'data/analytics/keys'import { useProjectDiskResizeMutation } from 'data/config/project-disk-resize-mutation'+import { useDiskAttributesQuery } from 'data/config/disk-attributes-query'import { useDatabaseSizeQuery } from 'data/database/database-size-query'+import { useMaxConnectionsQuery } from 'data/database/max-connections-query'+import { usePgbouncerConfigQuery } from 'data/database/pgbouncer-config-query'import { getReportAttributes, getReportAttributesV2 } from 'data/reports/database-charts'import { useDatabaseReport } from 'data/reports/database-report-query'import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'@@ -97,6 +100,13 @@ const DatabaseUsage = () => {const databaseSizeBytes = databaseSizeData ?? 0const currentDiskSize = project?.volumeSizeGb ?? 0+ const { data: diskConfig } = useDiskAttributesQuery({ projectRef: project?.ref })+ const { data: maxConnections } = useMaxConnectionsQuery({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ })+ const { data: poolerConfig } = usePgbouncerConfigQuery({ projectRef: project?.ref })+const { can: canUpdateDiskSizeConfig } = useAsyncCheckProjectPermissions(PermissionAction.UPDATE,'projects',@@ -107,8 +117,20 @@ const DatabaseUsage = () => {})- const REPORT_ATTRIBUTES = getReportAttributes(org!, project!)- const REPORT_ATTRIBUTES_V2 = getReportAttributesV2(org!, project!)+ const REPORT_ATTRIBUTES = getReportAttributes(+ org!,+ project!,+ diskConfig,+ maxConnections,+ poolerConfig+ )+ const REPORT_ATTRIBUTES_V2 = getReportAttributesV2(+ org!,+ project!,+ diskConfig,+ maxConnections,+ poolerConfig+ )const { isLoading: isUpdatingDiskSize } = useProjectDiskResizeMutation({onSuccess: (_, variables) => {