The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
realtime: add more settings to Realtime (#39566)
Filipe Cabaço1418fc9af65f
diff --git a/apps/docs/content/guides/realtime/settings.mdx b/apps/docs/content/guides/realtime/settings.mdxindex fab3055d3a5..6711f423ed8 100644--- a/apps/docs/content/guides/realtime/settings.mdx+++ b/apps/docs/content/guides/realtime/settings.mdx@@ -23,8 +23,11 @@ All changes made in this screen will disconnect all your connected clients to enYou can set the following settings using the Realtime Settings screen in your Dashboard:+- Suspend: Determines if the Realtime service is suspended- Channel Restrictions: You can toggle this settings to set Realtime to allow public channels or set it to use only private channels with [Realtime Authorization](/docs/guides/realtime/authorization).- Database connection pool size: Determines the number of connections used for Realtime Authorization RLS checking{/* supa-mdx-lint-disable-next-line Rule004ExcludeWords */}- Max concurrent clients: Determines the maximum number of clients that can be connected- Max events per second: Determines the maximum number of events per second that can be sent+- Max presence events per second: Determines the maximum number of presence events per second that can be sent+- Max payload size in KB: Determines the maximum number of payload size in KB that can be sentdiff --git a/apps/docs/public/img/guides/platform/realtime/realtime-settings--dark.png b/apps/docs/public/img/guides/platform/realtime/realtime-settings--dark.pngindex 8d3d73e420b..11c5dd8370f 100644Binary files a/apps/docs/public/img/guides/platform/realtime/realtime-settings--dark.png and b/apps/docs/public/img/guides/platform/realtime/realtime-settings--dark.png differdiff --git a/apps/docs/public/img/guides/platform/realtime/realtime-settings--light.png b/apps/docs/public/img/guides/platform/realtime/realtime-settings--light.pngindex fbb18d03013..38b04f9ebb5 100644Binary files a/apps/docs/public/img/guides/platform/realtime/realtime-settings--light.png and b/apps/docs/public/img/guides/platform/realtime/realtime-settings--light.png differdiff --git a/apps/studio/components/interfaces/Realtime/RealtimeSettings.tsx b/apps/studio/components/interfaces/Realtime/RealtimeSettings.tsxindex 26071ec4cd8..6068ee37c12 100644--- a/apps/studio/components/interfaces/Realtime/RealtimeSettings.tsx+++ b/apps/studio/components/interfaces/Realtime/RealtimeSettings.tsx@@ -64,7 +64,7 @@ export const RealtimeSettings = () => {const isFreePlan = organization?.plan.id === 'free'const isUsageBillingEnabled = organization?.usage_billing_enabled-+ const isRealtimeDisabed = data?.suspend ?? REALTIME_DEFAULT_CONFIG.suspend// Check if RLS policies exist for realtime.messages tableconst realtimeMessagesPolicies = policies?.filter((policy) => policy.schema === 'realtime' && policy.table === 'messages'@@ -87,6 +87,9 @@ export const RealtimeSettings = () => {.max(maxConn?.maxConnections ?? 100),max_concurrent_users: z.coerce.number().min(1).max(50000),max_events_per_second: z.coerce.number().min(1).max(10000),+ max_presence_events_per_second: z.coerce.number().min(1).max(10000),+ max_payload_size_in_kb: z.coerce.number().min(1).max(3000),+ suspend: z.boolean(),// [Joshen] These fields are temporarily hidden from the UI// max_bytes_per_second: z.coerce.number().min(1).max(10000000),// max_channels_per_client: z.coerce.number().min(1).max(10000),@@ -118,6 +121,9 @@ export const RealtimeSettings = () => {connection_pool: data.connection_pool,max_concurrent_users: data.max_concurrent_users,max_events_per_second: data.max_events_per_second,+ max_presence_events_per_second: data.max_presence_events_per_second,+ max_payload_size_in_kb: data.max_payload_size_in_kb,+ suspend: data.suspend,})}@@ -129,6 +135,53 @@ export const RealtimeSettings = () => {<AlertError error={error} subject="Failed to retrieve realtime settings" />) : (<Card>+ <CardContent>+ <FormField_Shadcn_+ control={form.control}+ name="suspend"+ render={({ field }) => (+ <FormSection+ className="!p-0 !pt-2"+ header={<FormSectionLabel>Enable Realtime service</FormSectionLabel>}+ >+ <FormSectionContent+ loaders={1}+ loading={isLoading || isLoadingPermissions}+ className="!gap-y-2"+ >+ <FormItemLayout+ layout="flex"+ label="Enable Realtime service"+ description="If enabled, all clients will be able to connect and new connections will be allowed"+ >+ <FormControl_Shadcn_>+ <Switch+ checked={!field.value}+ onCheckedChange={(checked) => field.onChange(!checked)}+ disabled={!canUpdateConfig}+ />+ </FormControl_Shadcn_>+ </FormItemLayout>+ <FormMessage_Shadcn_ />+ {isSuccessOrganization && isRealtimeDisabed && (+ <Admonition showIcon={false} type="default">+ <div className="flex items-center gap-x-2">+ <div>+ <h5 className="text-foreground mb-1">+ Realtime service is disabled+ </h5>+ <p className="text-foreground-light">+ You will need to enable it to continue using Realtime+ </p>+ </div>+ </div>+ </Admonition>+ )}+ </FormSectionContent>+ </FormSection>+ )}+ />+ </CardContent><CardContent><FormField_Shadcn_control={form.control}@@ -152,34 +205,37 @@ export const RealtimeSettings = () => {<Switchchecked={field.value}onCheckedChange={field.onChange}- disabled={!canUpdateConfig}+ disabled={!canUpdateConfig || isRealtimeDisabed}/></FormControl_Shadcn_></FormItemLayout>- {isSuccessPolicies && !hasRealtimeMessagesPolicies && !allow_public && (- <Admonition- showIcon={false}- type="warning"- title="No Realtime RLS policies found"- description={- <>- <p className="prose max-w-full text-sm">- Private mode is {isSettingToPrivate ? 'being ' : ''}- enabled, but no RLS policies exists on the{' '}- <code className="text-xs">realtime.messages</code> table. No- messages will be received by users.- </p>+ {isSuccessPolicies &&+ !hasRealtimeMessagesPolicies &&+ !allow_public &&+ !isRealtimeDisabed && (+ <Admonition+ showIcon={false}+ type="warning"+ title="No Realtime RLS policies found"+ description={+ <>+ <p className="prose max-w-full text-sm">+ Private mode is {isSettingToPrivate ? 'being ' : ''}+ enabled, but no RLS policies exists on the{' '}+ <code className="text-xs">realtime.messages</code> table. No+ messages will be received by users.+ </p>- <Button asChild type="default" className="mt-2">- <Link href={`/project/${projectRef}/realtime/policies`}>- Create policy- </Link>- </Button>- </>- }- />- )}+ <Button asChild type="default" className="mt-2">+ <Link href={`/project/${projectRef}/realtime/policies`}>+ Create policy+ </Link>+ </Button>+ </>+ }+ />+ )}</FormSectionContent></FormSection>)}@@ -209,7 +265,7 @@ export const RealtimeSettings = () => {<Input_Shadcn_{...field}type="number"- disabled={!canUpdateConfig}+ disabled={!canUpdateConfig || isRealtimeDisabed}value={field.value || ''}/></FormControl_Shadcn_>@@ -249,7 +305,12 @@ export const RealtimeSettings = () => {><FormSectionContent loaders={1} loading={isLoading} className="!gap-y-2"><FormControl_Shadcn_>- <Input_Shadcn_ {...field} type="number" value={field.value || ''} />+ <Input_Shadcn_+ {...field}+ type="number"+ disabled={!canUpdateConfig || isRealtimeDisabed}+ value={field.value || ''}+ /></FormControl_Shadcn_><FormMessage_Shadcn_ /></FormSectionContent>@@ -282,12 +343,134 @@ export const RealtimeSettings = () => {<Input_Shadcn_{...field}type="number"- disabled={!isUsageBillingEnabled || !canUpdateConfig}+ disabled={+ !isUsageBillingEnabled || !canUpdateConfig || isRealtimeDisabed+ }+ value={field.value || ''}+ />+ </FormControl_Shadcn_>+ <FormMessage_Shadcn_ />+ {isSuccessOrganization && !isUsageBillingEnabled && !isRealtimeDisabed && (+ <Admonition showIcon={false} type="default">+ <div className="flex items-center gap-x-2">+ <div>+ <h5 className="text-foreground mb-1">+ Spend cap needs to be disabled to configure this value+ </h5>+ <p className="text-foreground-light">+ {isFreePlan+ ? 'Upgrade to the Pro plan first to disable spend cap'+ : 'You may adjust this setting in the organization billing settings'}+ </p>+ </div>+ <div className="flex-grow flex items-center justify-end">+ {isFreePlan ? (+ <UpgradePlanButton source="realtimeSettings" plan="Pro" />+ ) : (+ <ToggleSpendCapButton />+ )}+ </div>+ </div>+ </Admonition>+ )}+ </FormSectionContent>+ </FormSection>+ )}+ />+ </CardContent>+ <CardContent>+ <FormField_Shadcn_+ control={form.control}+ name="max_presence_events_per_second"+ render={({ field }) => (+ <FormSection+ className="!p-0 !py-2"+ header={+ <FormSectionLabel+ description={+ <p className="text-foreground-lighter text-sm !mt-1">+ Sets maximum number of presence events per second that can be sent to+ your Realtime service+ </p>+ }+ >+ Max presence events per second+ </FormSectionLabel>+ }+ >+ <FormSectionContent loaders={1} loading={isLoading} className="!gap-y-2">+ <FormControl_Shadcn_>+ <Input_Shadcn_+ {...field}+ type="number"+ disabled={+ !isUsageBillingEnabled || !canUpdateConfig || isRealtimeDisabed+ }+ value={field.value || ''}+ />+ </FormControl_Shadcn_>+ <FormMessage_Shadcn_ />+ {isSuccessOrganization && !isUsageBillingEnabled && !isRealtimeDisabed && (+ <Admonition showIcon={false} type="default">+ <div className="flex items-center gap-x-2">+ <div>+ <h5 className="text-foreground mb-1">+ Spend cap needs to be disabled to configure this value+ </h5>+ <p className="text-foreground-light">+ {isFreePlan+ ? 'Upgrade to the Pro plan first to disable spend cap'+ : 'You may adjust this setting in the organization billing settings'}+ </p>+ </div>+ <div className="flex-grow flex items-center justify-end">+ {isFreePlan ? (+ <UpgradePlanButton source="realtimeSettings" plan="Pro" />+ ) : (+ <ToggleSpendCapButton />+ )}+ </div>+ </div>+ </Admonition>+ )}+ </FormSectionContent>+ </FormSection>+ )}+ />+ </CardContent>+ <CardContent>+ <FormField_Shadcn_+ control={form.control}+ name="max_payload_size_in_kb"+ render={({ field }) => (+ <FormSection+ className="!p-0 !py-2"+ header={+ <FormSectionLabel+ description={+ <p className="text-foreground-lighter text-sm !mt-1">+ Sets maximum number of payload size in KB that can be sent to your+ Realtime service+ </p>+ }+ >+ Max payload size in KB+ </FormSectionLabel>+ }+ >+ <FormSectionContent loaders={1} loading={isLoading} className="!gap-y-2">+ <FormControl_Shadcn_>+ <Input_Shadcn_+ {...field}+ type="number"+ disabled={+ !isUsageBillingEnabled || !canUpdateConfig || isRealtimeDisabed+ }value={field.value || ''}/></FormControl_Shadcn_><FormMessage_Shadcn_ />- {isSuccessOrganization && !isUsageBillingEnabled && (+ {isSuccessOrganization && !isUsageBillingEnabled && !isRealtimeDisabed && (<Admonition showIcon={false} type="default"><div className="flex items-center gap-x-2"><div>diff --git a/apps/studio/data/realtime/realtime-config-mutation.ts b/apps/studio/data/realtime/realtime-config-mutation.tsindex 6d380b5dcea..9629e76c794 100644--- a/apps/studio/data/realtime/realtime-config-mutation.ts+++ b/apps/studio/data/realtime/realtime-config-mutation.ts@@ -19,6 +19,9 @@ export async function updateRealtimeConfiguration({max_bytes_per_second,max_channels_per_client,max_joins_per_second,+ max_presence_events_per_second,+ max_payload_size_in_kb,+ suspend,}: RealtimeConfigurationUpdateVariables) {if (!ref) return console.error('Project ref is required')@@ -32,6 +35,9 @@ export async function updateRealtimeConfiguration({max_bytes_per_second,max_channels_per_client,max_joins_per_second,+ max_presence_events_per_second,+ max_payload_size_in_kb,+ suspend,},})diff --git a/apps/studio/data/realtime/realtime-config-query.ts b/apps/studio/data/realtime/realtime-config-query.tsindex fa03f6f5840..f9677d13d48 100644--- a/apps/studio/data/realtime/realtime-config-query.ts+++ b/apps/studio/data/realtime/realtime-config-query.ts@@ -17,6 +17,9 @@ export const REALTIME_DEFAULT_CONFIG = {max_bytes_per_second: 100000,max_channels_per_client: 100,max_joins_per_second: 100,+ max_presence_events_per_second: 100,+ max_payload_size_in_kb: 100,+ suspend: false,}export async function getRealtimeConfiguration(