Skip to content

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

ref(replication): Improve replication copy and UI (#46793)

Riccardo Busetti324c72411766
diff --git a/apps/studio/components/interfaces/Database/Replication/DeleteDestination.tsx b/apps/studio/components/interfaces/Database/Replication/DeleteDestination.tsx
index 2489f405355..0fddb5a6b18 100644
--- a/apps/studio/components/interfaces/Database/Replication/DeleteDestination.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DeleteDestination.tsx
@@ -24,7 +24,7 @@ export const DeleteDestination = ({
confirmLabel={isLoading ? 'Deleting...' : `Delete destination`}
confirmPlaceholder="Type in name of destination"
confirmString={name ?? 'Unknown'}
- text={`This will delete the destination "${name}"`}
+ text={`This will delete the destination "${name}".`}
alert={{ title: 'You cannot recover this destination once deleted.' }}
onCancel={() => setVisible(!visible)}
onConfirm={onDelete}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
index 3f909475df8..cba27702b7a 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
@@ -43,7 +43,7 @@ export const AdvancedSettings = ({
<div className="flex flex-col items-start gap-0.5">
<span className="text-sm font-medium">Advanced settings</span>
<span className="text-sm text-foreground-lighter font-normal">
- Optional performance tuning
+ Optional settings to control the pipeline in more depth
</span>
</div>
</AccordionTrigger>
@@ -165,7 +165,7 @@ export const AdvancedSettings = ({
<FormItemLayout
label="Invalidated slot behavior"
layout="horizontal"
- description="Behavior when the replication slot is invalidated"
+ description="Behavior of the pipeline's replication slot when invalidated."
>
<FormControl>
<Select value={field.value ?? 'error'} onValueChange={field.onChange}>
@@ -174,13 +174,13 @@ export const AdvancedSettings = ({
<SelectItem value="error" className="[&>span]:top-2.5">
<p>Error</p>
<p className="text-foreground-lighter">
- Blocks startup for manual recovery
+ Blocks startup for manual recovery.
</p>
</SelectItem>
<SelectItem value="recreate" className="[&>span]:top-2.5">
<p>Recreate</p>
<p className="text-foreground-lighter">
- Rebuilds the slot and restarts replication from scratch
+ Rebuilds the slot and restarts replication from scratch.
</p>
</SelectItem>
</SelectContent>
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NoDestinationsAvailable.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NoDestinationsAvailable.tsx
index 617e6f6877e..ba0f19e5198 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NoDestinationsAvailable.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NoDestinationsAvailable.tsx
@@ -9,7 +9,7 @@ export const NoDestinationsAvailable = () => {
<h3 className="text-lg font-medium text-foreground mb-2">No destinations available</h3>
<p className="text-sm text-foreground-light max-w-lg">
Replication destinations are not currently enabled for this project. Contact support to
- enable real-time replication to external platforms.
+ enable real-time replication to external destinations.
</p>
</div>
)
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsx
index f96b0e28e45..903cd14daa1 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsx
@@ -42,7 +42,7 @@ export const PublicationSelection = ({
<FormItemLayout
layout="horizontal"
label="Publication"
- description="Tables in the selected publication will be replicated to this destination"
+ description="Tables in the selected publication will be replicated to this destination."
>
<FormControl>
<PublicationsComboBox
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/ReplicationDisclaimerDialog.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/ReplicationDisclaimerDialog.tsx
index 0743f85b54a..060e53892ca 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/ReplicationDisclaimerDialog.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/ReplicationDisclaimerDialog.tsx
@@ -32,8 +32,8 @@ export const ReplicationDisclaimerDialog = ({
<DialogSection className="space-y-4 text-sm">
<p className="text-foreground">
Creating this replication pipeline will immediately start syncing data from your
- publication into the destination. Make sure you understand the limitations of the system
- before proceeding.
+ publication into an external destination. Review the current limitations before
+ proceeding.
</p>
<div className="text-foreground-light">
@@ -53,10 +53,6 @@ export const ReplicationDisclaimerDialog = ({
With FULL replica identity deletes and updates include the payload that is needed to
correctly apply those changes.
</li>
- <li>
- <strong className="text-foreground">Schema changes aren’t supported yet.</strong>{' '}
- Plan for manual adjustments if you need to alter replicated tables.
- </li>
</ul>
</div>
</DialogSection>
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
index adef6160f4d..eee3e2f9b0e 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationPanel.tsx
@@ -104,7 +104,7 @@ export const DestinationPanel = ({ onSuccessCreateReadReplica }: DestinationPane
<SheetDescription>
{editMode
? 'Update the configuration for this destination'
- : 'A destination can be a read replica or an external platform that receives your database changes in real time.'}
+ : 'A destination can be a read replica or an external destination that receives your database changes in real time.'}
</SheetDescription>
</SheetHeader>
@@ -118,11 +118,11 @@ export const DestinationPanel = ({ onSuccessCreateReadReplica }: DestinationPane
<SheetSection>
<div className={cn('border rounded-md p-6 flex flex-col gap-y-4')}>
<div className="flex flex-col gap-y-1">
- <h4>Replicate data to external destinations in real-time</h4>
+ <h4>Replicate data to external destinations in real time</h4>
<p className="text-sm text-foreground-light">
- We are currently in <span className="text-foreground">private alpha</span> and
- slowly onboarding new customers to ensure stable data pipelines. Request
- access below to join the waitlist. Read replicas are available now.
+ External destinations are in <span className="text-foreground">alpha</span>{' '}
+ and are being rolled out gradually. Request access below to join the waitlist.
+ Read replicas are available now.
</p>
</div>
<div className="flex gap-x-2">
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.test.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.test.tsx
new file mode 100644
index 00000000000..358bda15eac
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.test.tsx
@@ -0,0 +1,160 @@
+import { fireEvent, screen } from '@testing-library/react'
+import { platformComponents as components } from 'api-types'
+import { mockAnimationsApi } from 'jsdom-testing-mocks'
+import { HttpResponse } from 'msw'
+import { describe, expect, test, vi } from 'vitest'
+
+import { DestinationTypeSelection } from './DestinationTypeSelection'
+import { customRender } from '@/tests/lib/custom-render'
+import { addAPIMock } from '@/tests/lib/msw'
+
+type ReplicationSourcesResponse = components['schemas']['ReplicationSourcesResponse']
+type ReplicationPipelinesResponse = components['schemas']['ReplicationPipelinesResponse']
+type ReplicationDestinationResponse = components['schemas']['ReplicationDestinationResponse']
+
+mockAnimationsApi()
+
+// Feature flags are not API calls — mock at the module level so tests can
+// control per-destination-type visibility without hitting PostHog.
+const mockBigQueryEnabled = vi.fn()
+const mockIcebergEnabled = vi.fn()
+const mockDucklakeEnabled = vi.fn()
+const mockSnowflakeEnabled = vi.fn()
+
+vi.mock('../useIsETLPrivateAlpha', () => ({
+ useIsETLBigQueryPrivateAlpha: () => mockBigQueryEnabled(),
+ useIsETLIcebergPrivateAlpha: () => mockIcebergEnabled(),
+ useIsETLDucklakePrivateAlpha: () => mockDucklakeEnabled(),
+ useIsETLSnowflakePrivateAlpha: () => mockSnowflakeEnabled(),
+}))
+
+vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
+ useIsFeatureEnabled: () => ({ infrastructureReadReplicas: true }),
+}))
+
+// Background queries from useDestinationInformation (sources + pipelines fire
+// even in create mode). Prevent retries so unmatched handlers fail fast.
+vi.mock('@/data/replication/utils', () => ({
+ checkReplicationFeatureFlagRetry: () => false,
+}))
+
+const addBackgroundMocks = () => {
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/sources',
+ response: () => HttpResponse.json<ReplicationSourcesResponse>({ sources: [] }),
+ })
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/pipelines',
+ response: () => HttpResponse.json<ReplicationPipelinesResponse>({ pipelines: [] }),
+ })
+}
+
+describe('DestinationTypeSelection', () => {
+ test('shows placeholder when no type is selected', async () => {
+ mockBigQueryEnabled.mockReturnValue(false)
+ mockIcebergEnabled.mockReturnValue(false)
+ mockDucklakeEnabled.mockReturnValue(false)
+ mockSnowflakeEnabled.mockReturnValue(false)
+ addBackgroundMocks()
+
+ customRender(<DestinationTypeSelection />)
+
+ expect(await screen.findByText('Select a destination type')).toBeInTheDocument()
+ })
+
+ test('renders the Within Supabase group with Read Replica when dropdown is opened', async () => {
+ mockBigQueryEnabled.mockReturnValue(false)
+ mockIcebergEnabled.mockReturnValue(false)
+ mockDucklakeEnabled.mockReturnValue(false)
+ mockSnowflakeEnabled.mockReturnValue(false)
+ addBackgroundMocks()
+
+ customRender(<DestinationTypeSelection />)
+
+ fireEvent.click(await screen.findByRole('combobox'))
+
+ expect(await screen.findByText('Within Supabase')).toBeInTheDocument()
+ expect(screen.getByText('Read Replica')).toBeInTheDocument()
+ })
+
+ test('renders the Outside Supabase group with BigQuery when the flag is enabled', async () => {
+ mockBigQueryEnabled.mockReturnValue(true)
+ mockIcebergEnabled.mockReturnValue(false)
+ mockDucklakeEnabled.mockReturnValue(false)
+ mockSnowflakeEnabled.mockReturnValue(false)
+ addBackgroundMocks()
+
+ customRender(<DestinationTypeSelection />)
+
+ fireEvent.click(await screen.findByRole('combobox'))
+
+ expect(await screen.findByText('Outside Supabase')).toBeInTheDocument()
+ expect(screen.getByText('BigQuery')).toBeInTheDocument()
+ })
+
+ test('hides destinations behind disabled feature flags', async () => {
+ mockBigQueryEnabled.mockReturnValue(false)
+ mockIcebergEnabled.mockReturnValue(false)
+ mockDucklakeEnabled.mockReturnValue(false)
+ mockSnowflakeEnabled.mockReturnValue(false)
+ addBackgroundMocks()
+
+ customRender(<DestinationTypeSelection />)
+
+ fireEvent.click(await screen.findByRole('combobox'))
+
+ await screen.findByText('Within Supabase')
+ expect(screen.queryByText('BigQuery')).not.toBeInTheDocument()
+ expect(screen.queryByText('DuckLake')).not.toBeInTheDocument()
+ expect(screen.queryByText('Analytics Bucket')).not.toBeInTheDocument()
+ expect(screen.queryByText('Outside Supabase')).not.toBeInTheDocument()
+ })
+
+ test('shows alpha warning when an alpha destination type is selected', async () => {
+ mockBigQueryEnabled.mockReturnValue(true)
+ mockIcebergEnabled.mockReturnValue(false)
+ mockDucklakeEnabled.mockReturnValue(false)
+ mockSnowflakeEnabled.mockReturnValue(false)
+ addBackgroundMocks()
+
+ customRender(<DestinationTypeSelection />)
+
+ fireEvent.click(await screen.findByRole('combobox'))
+ fireEvent.click(await screen.findByText('BigQuery'))
+
+ expect(await screen.findByText(/This destination type is in alpha/)).toBeInTheDocument()
+ })
+
+ test('disables the selector in edit mode so the destination type cannot be changed', async () => {
+ mockBigQueryEnabled.mockReturnValue(true)
+ mockIcebergEnabled.mockReturnValue(false)
+ mockDucklakeEnabled.mockReturnValue(false)
+ mockSnowflakeEnabled.mockReturnValue(false)
+ addBackgroundMocks()
+ // Edit mode triggers useDestinationInformation({ id: 1 }) which fires destination-by-id
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/destinations/:destination_id',
+ response: () =>
+ HttpResponse.json<ReplicationDestinationResponse>({
+ tenant_id: 't',
+ id: 1,
+ name: 'My BigQuery Destination',
+ config: {
+ big_query: {
+ project_id: 'gcp-proj',
+ dataset_id: 'analytics',
+ service_account_key: '{}',
+ },
+ },
+ }),
+ })
+
+ // ?edit=1 locks the type to the existing destination
+ customRender(<DestinationTypeSelection />, { nuqs: { searchParams: { edit: '1' } } })
+
+ expect(await screen.findByRole('combobox')).toBeDisabled()
+ })
+})
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.tsx
index 38f15c5c954..01abedb6c6b 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationTypeSelection.tsx
@@ -1,7 +1,15 @@
import { AnalyticsBucket, BigQuery, Database } from 'icons'
import { Snowflake } from 'lucide-react'
import { parseAsInteger, parseAsStringEnum, useQueryState } from 'nuqs'
-import { Badge, cn, RadioGroupStacked, RadioGroupStackedItem } from 'ui'
+import {
+ Badge,
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectLabel,
+ SelectTrigger,
+} from 'ui'
import { useDestinationInformation } from '../useDestinationInformation'
import {
@@ -14,6 +22,20 @@ import { DestinationType } from './DestinationPanel.types'
import { InlineLink } from '@/components/ui/InlineLink'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
+interface DestinationTypeOption {
+ value: DestinationType
+ label: string
+ description: string
+ icon: typeof Database
+ isAlpha: boolean
+ enabled: boolean
+}
+
+interface DestinationTypeGroup {
+ label: string
+ options: DestinationTypeOption[]
+}
+
export const DestinationTypeSelection = () => {
const etlEnableBigQuery = useIsETLBigQueryPrivateAlpha()
const etlEnableIceberg = useIsETLIcebergPrivateAlpha()
@@ -21,14 +43,6 @@ export const DestinationTypeSelection = () => {
const etlEnableSnowflake = useIsETLSnowflakePrivateAlpha()
const { infrastructureReadReplicas } = useIsFeatureEnabled(['infrastructure:read_replicas'])
- const numberOfTypes = [
- infrastructureReadReplicas,
- etlEnableBigQuery,
- etlEnableIceberg,
- etlEnableDucklake,
- etlEnableSnowflake,
- ].filter(Boolean).length
-
const [urlDestinationType, setDestinationType] = useQueryState(
'destinationType',
parseAsStringEnum<DestinationType>([
@@ -52,132 +66,127 @@ export const DestinationTypeSelection = () => {
const { type: existingDestinationType } = useDestinationInformation({ id: edit })
const destinationType = existingDestinationType ?? urlDestinationType
+ // In edit mode the type is locked, so only surface the option that matches the
+ // destination being edited. Otherwise show every type the project has access to.
+ const isOptionVisible = (value: DestinationType, hasAccess: boolean) =>
+ editMode ? destinationType === value : hasAccess
+
+ const groups: DestinationTypeGroup[] = [
+ {
+ label: 'Within Supabase',
+ options: [
+ {
+ value: 'Read Replica',
+ label: 'Read Replica',
+ description:
+ 'Deploy a read-only database in another region for lower latency and workload isolation',
+ icon: Database,
+ isAlpha: false,
+ enabled: isOptionVisible('Read Replica', infrastructureReadReplicas),
+ },
+ {
+ value: 'Analytics Bucket',
+ label: 'Analytics Bucket',
+ description: 'Write Apache Iceberg tables to Supabase Storage for analytics workflows',
+ icon: AnalyticsBucket,
+ isAlpha: true,
+ enabled: isOptionVisible('Analytics Bucket', etlEnableIceberg),
+ },
+ ],
+ },
+ {
+ label: 'Outside Supabase',
+ options: [
+ {
+ value: 'BigQuery',
+ label: 'BigQuery',
+ description: "Stream changes to Google Cloud's data warehouse for analytics and BI",
+ icon: BigQuery,
+ isAlpha: true,
+ enabled: isOptionVisible('BigQuery', etlEnableBigQuery),
+ },
+ {
+ value: 'DuckLake',
+ label: 'DuckLake',
+ description: 'Stream changes to a DuckLake catalog backed by S3-compatible storage',
+ icon: Database,
+ isAlpha: true,
+ enabled: isOptionVisible('DuckLake', etlEnableDucklake),
+ },
+ {
+ value: 'Snowflake',
+ label: 'Snowflake',
+ description:
+ 'Stream changes to Snowflake for warehouse analytics and downstream data workflows',
+ icon: Snowflake,
+ isAlpha: true,
+ enabled: isOptionVisible('Snowflake', etlEnableSnowflake),
+ },
+ ],
+ },
+ ]
+
+ const visibleGroups = groups
+ .map((group) => ({ ...group, options: group.options.filter((option) => option.enabled) }))
+ .filter((group) => group.options.length > 0)
+
+ const selectedOption = visibleGroups
+ .flatMap((group) => group.options)
+ .find((option) => option.value === destinationType)
+
return (
- <div className="px-5 py-5">
- <div className="flex flex-col gap-y-1 mb-4">
+ <div className="flex flex-col gap-y-2 p-5">
+ <div className="flex flex-col gap-y-1">
<p className="text-sm font-medium text-foreground">Type</p>
- <p className="text-foreground-light text-sm">
- The destination type cannot be changed after creation
+ <p className="text-sm text-foreground-light">
+ The destination type cannot be changed after creation.
</p>
</div>
- <RadioGroupStacked
+
+ <Select
disabled={editMode}
- value={destinationType}
+ value={destinationType ?? undefined}
onValueChange={(value) => setDestinationType(value as DestinationType)}
- className={cn(
- 'grid [&>button>div]:py-4',
- !editMode && numberOfTypes >= 5
- ? 'grid-cols-5'
- : !editMode && numberOfTypes === 4
- ? 'grid-cols-4'
- : !editMode && numberOfTypes === 3
- ? 'grid-cols-3'
- : 'grid-cols-2',
- '[&>button:first-of-type]:rounded-none [&>button:last-of-type]:rounded-none',
- '[&>button:first-of-type]:rounded-l-lg! [&>button:last-of-type]:rounded-r-lg!'
- )}
>
- {((!editMode && infrastructureReadReplicas) ||
- (editMode && destinationType === 'Read Replica')) && (
- <RadioGroupStackedItem
- label=""
- showIndicator={false}
- id="Read Replica"
- value="Read Replica"
- >
- <div className="flex flex-col gap-y-2">
- <Database size={20} />
- <div className="flex flex-col gap-y-0.5 text-sm text-left">
- <p>Read Replica</p>
- <p className="text-foreground-lighter">
- Deploy read-only databases across multiple regions for lower latency and better
- resource management
- </p>
- </div>
- </div>
- </RadioGroupStackedItem>
- )}
-
- {((!editMode && etlEnableBigQuery) || (editMode && destinationType === 'BigQuery')) && (
- <RadioGroupStackedItem label="" showIndicator={false} id="BigQuery" value="BigQuery">
- <div className="flex flex-col gap-y-2">
- <BigQuery size={20} />
- <div className="flex flex-col gap-y-0.5 text-sm text-left">
- <div className="flex items-center gap-x-2">
- <p>BigQuery</p>
- <Badge>Alpha</Badge>
- </div>
- <p className="text-foreground-lighter">
- Send data to Google Cloud's data warehouse for analytics and business intelligence
- </p>
- </div>
- </div>
- </RadioGroupStackedItem>
- )}
-
- {((!editMode && etlEnableIceberg) ||
- (editMode && destinationType === 'Analytics Bucket')) && (
- <RadioGroupStackedItem
- label=""
- showIndicator={false}
- id="Analytics Bucket"
- value="Analytics Bucket"
- >
- <div className="flex flex-col gap-y-2">
- <AnalyticsBucket size={20} />
- <div className="flex flex-col gap-y-0.5 text-sm text-left">
- <div className="flex items-center gap-x-2">
- <p>Analytics Bucket</p>
- <Badge>Alpha</Badge>
- </div>
- <p className="text-foreground-lighter">
- Send data to Apache Iceberg tables in your Supabase Storage for flexible analytics
- workflows
- </p>
- </div>
- </div>
- </RadioGroupStackedItem>
- )}
-
- {((!editMode && etlEnableDucklake) || (editMode && destinationType === 'DuckLake')) && (
- <RadioGroupStackedItem label="" showIndicator={false} id="DuckLake" value="DuckLake">
- <div className="flex flex-col gap-y-2">
- <Database size={20} />
- <div className="flex flex-col gap-y-0.5 text-sm text-left">
- <div className="flex items-center gap-x-2">
- <p>DuckLake</p>
- <Badge>Alpha</Badge>
- </div>
- <p className="text-foreground-lighter">
- Send data to a DuckLake catalog backed by S3-compatible object storage for
- flexible lakehouse workflows
- </p>
- </div>
- </div>
- </RadioGroupStackedItem>
- )}
-
- {((!editMode && etlEnableSnowflake) || (editMode && destinationType === 'Snowflake')) && (
- <RadioGroupStackedItem label="" showIndicator={false} id="Snowflake" value="Snowflake">
- <div className="flex flex-col gap-y-2">
- <Snowflake size={20} />
- <div className="flex flex-col gap-y-0.5 text-sm text-left">
- <div className="flex items-center gap-x-2">
- <p>Snowflake</p>
- <Badge>Alpha</Badge>
- </div>
- <p className="text-foreground-lighter">
- Send data to Snowflake for warehouse analytics and downstream data workflows
- </p>
+ <SelectTrigger className="h-auto py-2">
+ {selectedOption ? (
+ <div className="flex items-center gap-x-3 text-left">
+ <selectedOption.icon size={20} className="shrink-0 text-foreground-light" />
+ <div className="flex items-center gap-x-2">
+ <span className="text-sm text-foreground">{selectedOption.label}</span>
+ {selectedOption.isAlpha && <Badge variant="warning">Alpha</Badge>}
</div>
</div>
- </RadioGroupStackedItem>
- )}
- </RadioGroupStacked>
+ ) : (
+ <span className="text-foreground-lighter">Select a destination type</span>
+ )}
+ </SelectTrigger>
+ <SelectContent>
+ {visibleGroups.map((group) => (
+ <SelectGroup key={group.label}>
+ <SelectLabel>{group.label}</SelectLabel>
+ {group.options.map((option) => (
+ <SelectItem key={option.value} value={option.value} className="py-2">
+ <div className="flex items-center gap-x-3">
+ <option.icon size={20} className="shrink-0 text-foreground-light" />
+ <div className="flex flex-col gap-y-0.5">
+ <div className="flex items-center gap-x-2">
+ <span className="text-foreground">{option.label}</span>
+ {option.isAlpha && <Badge variant="warning">Alpha</Badge>}
+ </div>
+ <span className="text-xs text-foreground-lighter">{option.description}</span>
+ </div>
+ </div>
+ </SelectItem>
+ ))}
+ </SelectGroup>
+ ))}
+ </SelectContent>
+ </Select>
- {destinationType !== 'Read Replica' && (
- <p className="mt-3 text-sm text-foreground-light">
- External replication is in alpha. Expect rapid changes and possible breaking updates.{' '}
+ {selectedOption?.isAlpha && (
+ <p className="text-sm text-foreground-light">
+ This destination type is in alpha and may change while we iterate.{' '}
<InlineLink href="https://github.com/orgs/supabase/discussions/39416">
Leave feedback
</InlineLink>
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx
index ed01b16a504..370d235c8a8 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx
@@ -65,7 +65,7 @@ export const ReadReplicaEligibilityWarnings = () => {
if (hasOverdueInvoices) {
return (
<Admonition type="warning" title="Your organization has overdue invoices">
- <p>Please resolve all outstanding invoices first before deploying a new read replica</p>
+ <p>Please resolve all outstanding invoices first before deploying a new read replica.</p>
<Button asChild type="default" className="mt-2">
<Link href={`/org/${org?.slug}/billing#invoices`}>View invoices</Link>
</Button>
@@ -81,7 +81,7 @@ export const ReadReplicaEligibilityWarnings = () => {
>
<p>
Projects provisioned by other cloud providers currently will not be able to use read
- replicas
+ replicas.
</p>
<DocsButton
abbrev={false}
@@ -97,7 +97,7 @@ export const ReadReplicaEligibilityWarnings = () => {
<Admonition
type="warning"
title="Read replicas are not supported for AWS (Revamped) projects"
- description="Projects provisioned by other cloud providers currently will not be able to use read replicas"
+ description="Projects provisioned by other cloud providers currently will not be able to use read replicas."
/>
)
}
@@ -108,7 +108,7 @@ export const ReadReplicaEligibilityWarnings = () => {
type="warning"
title="Read replicas can only be deployed with projects on Postgres version 15 and above"
>
- <p>If you'd like to use read replicas, please contact us via support</p>
+ <p>If you'd like to use read replicas, please contact us via support.</p>
<Button asChild type="default" className="mt-2">
<SupportLink
queryParams={{
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationRow.test.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationRow.test.tsx
new file mode 100644
index 00000000000..d3e34656cd2
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationRow.test.tsx
@@ -0,0 +1,280 @@
+import { screen } from '@testing-library/react'
+import { platformComponents as components } from 'api-types'
+import { mockAnimationsApi } from 'jsdom-testing-mocks'
+import { HttpResponse } from 'msw'
+import { describe, expect, test, vi } from 'vitest'
+
+import { DestinationRow } from './DestinationRow'
+import { customRender } from '@/tests/lib/custom-render'
+import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
+
+type ReplicationPipelinesResponse = components['schemas']['ReplicationPipelinesResponse']
+type ReplicationDestinationResponse = components['schemas']['ReplicationDestinationResponse']
+type ReplicationSourcesResponse = components['schemas']['ReplicationSourcesResponse']
+type ReplicationPipelineStatusResponse = components['schemas']['ReplicationPipelineStatusResponse']
+type ReplicationPipelineReplicationStatusResponse =
+ components['schemas']['ReplicationPipelineReplicationStatusResponse']
+type ReplicationPipelineVersionResponse =
+ components['schemas']['ReplicationPipelineVersionResponse']
+
+// Tooltip/Popover descendants use Web Animations
+mockAnimationsApi()
+
+// Prevent retries on mocked error responses — replication queries override the
+// QueryClient default with checkReplicationFeatureFlagRetry, which retries up to
+// 3 times. Without this mock error tests would time-out.
+vi.mock('@/data/replication/utils', () => ({
+ checkReplicationFeatureFlagRetry: () => false,
+}))
+
+// DestinationRow requires a PipelineRequestStatusContext provider.
+// Mock the module so tests don't need to wrap with the provider.
+vi.mock('@/state/replication-pipeline-request-status', () => ({
+ PipelineStatusRequestStatus: {
+ None: 'None',
+ StartRequested: 'StartRequested',
+ StopRequested: 'StopRequested',
+ RestartRequested: 'RestartRequested',
+ },
+ usePipelineRequestStatus: () => ({
+ getRequestStatus: () => 'None',
+ updatePipelineStatus: () => {},
+ }),
+}))
+
+const DESTINATION_ID = 1
+const PIPELINE_ID = 42
+
+const addSourcesMock = () =>
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/sources',
+ response: () =>
+ HttpResponse.json<ReplicationSourcesResponse>({
+ sources: [
+ {
+ tenant_id: 't',
+ id: 1,
+ name: 'default',
+ config: { host: 'db.internal', port: 5432, name: 'main-db', username: 'etl_user' },
+ },
+ ],
+ }),
+ })
+
+const addDestinationMock = () =>
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/destinations/:destination_id',
+ response: () =>
+ HttpResponse.json<ReplicationDestinationResponse>({
+ tenant_id: 't',
+ id: DESTINATION_ID,
+ name: 'My BigQuery Destination',
+ config: {
+ big_query: { project_id: 'gcp-proj', dataset_id: 'analytics', service_account_key: '{}' },
+ },
+ }),
+ })
+
+const addPipelinesMock = () =>
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/pipelines',
+ response: () =>
+ HttpResponse.json<ReplicationPipelinesResponse>({
+ pipelines: [
+ {
+ id: PIPELINE_ID,
+ tenant_id: 't',
+ source_id: 1,
+ source_name: 'main-db',
+ destination_id: DESTINATION_ID,
+ destination_name: 'My BigQuery Destination',
+ replicator_id: 9001,
+ config: { publication_name: 'supabase_realtime' },
+ },
+ ],
+ }),
+ })
+
+const addPipelineStatusMock = (statusName: ReplicationPipelineStatusResponse['status']['name']) =>
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/pipelines/:pipeline_id/status',
+ response: () =>
+ HttpResponse.json<ReplicationPipelineStatusResponse>({
+ pipeline_id: PIPELINE_ID,
+ status: { name: statusName },
+ }),
+ })
+
+const addReplicationStatusMock = (
+ confirmedFlushLsnBytes: number,
+ tableStatuses: ReplicationPipelineReplicationStatusResponse['table_statuses'] = []
+) =>
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/pipelines/:pipeline_id/replication-status',
+ response: () =>
+ HttpResponse.json<ReplicationPipelineReplicationStatusResponse>({
+ pipeline_id: PIPELINE_ID,
+ apply_lag: {
+ active: true,
+ wal_status: 'reserved',
+ restart_lsn_bytes: 0,
+ confirmed_flush_lsn_bytes: confirmedFlushLsnBytes,
+ safe_wal_size_bytes: null,
+ },
+ table_statuses: tableStatuses,
+ }),
+ })
+
+const addVersionMock = () =>
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/pipelines/:pipeline_id/version',
+ response: () =>
+ HttpResponse.json<ReplicationPipelineVersionResponse>({
+ pipeline_id: PIPELINE_ID,
+ version: { id: 1, name: 'v0.3.0' },
+ }),
+ })
+
+describe('DestinationRow', () => {
+ test('shows "Caught up" when confirmed_flush_lsn_bytes is 0', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('started')
+ addReplicationStatusMock(0)
+ addVersionMock()
+
+ customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ expect(await screen.findByText('Caught up')).toBeInTheDocument()
+ })
+
+ test('shows formatted lag value when confirmed_flush_lsn_bytes is non-zero', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('started')
+ addReplicationStatusMock(2048)
+ addVersionMock()
+
+ customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ expect(await screen.findByText('2 KB')).toBeInTheDocument()
+ })
+
+ test('shows publication name from pipeline config', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('started')
+ addReplicationStatusMock(0)
+ addVersionMock()
+
+ customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ expect(await screen.findByText('supabase_realtime')).toBeInTheDocument()
+ })
+
+ test('shows Running badge when pipeline is started', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('started')
+ addReplicationStatusMock(0)
+ addVersionMock()
+
+ customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ expect(await screen.findByText('Running')).toBeInTheDocument()
+ })
+
+ test('shows Failed badge when pipeline has failed', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('failed')
+ addReplicationStatusMock(0)
+ addVersionMock()
+
+ customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ expect(await screen.findByText('Failed')).toBeInTheDocument()
+ })
+
+ test('shows Stopped badge when pipeline is stopped', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('stopped')
+ addReplicationStatusMock(0)
+ addVersionMock()
+
+ customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ expect(await screen.findByText('Stopped')).toBeInTheDocument()
+ })
+
+ test('shows warning icon when tables have replication errors', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('started')
+ addReplicationStatusMock(0, [
+ {
+ table_id: 1,
+ table_name: 'public.orders',
+ state: { name: 'error', reason: 'table not found', retry_policy: { policy: 'no_retry' } },
+ },
+ ])
+ addVersionMock()
+
+ const { container } = customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ await screen.findByText('Caught up')
+
+ // WarningIcon renders with bg-warning-600 (from packages/ui/src/components/StatusIcon.tsx)
+ expect(container.querySelector('.bg-warning-600')).toBeInTheDocument()
+ })
+
+ test('suppresses warning icon when pipeline is stopped even with table errors', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addPipelinesMock()
+ addPipelineStatusMock('stopped')
+ addReplicationStatusMock(0, [
+ {
+ table_id: 1,
+ table_name: 'public.orders',
+ state: { name: 'error', reason: 'table not found', retry_policy: { policy: 'no_retry' } },
+ },
+ ])
+ addVersionMock()
+
+ const { container } = customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ await screen.findByText('Stopped')
+
+ expect(container.querySelector('.bg-warning-600')).not.toBeInTheDocument()
+ })
+
+ test('shows error when the pipelines API fails', async () => {
+ addSourcesMock()
+ addDestinationMock()
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/pipelines',
+ response: () =>
+ HttpResponse.json<APIErrorBody>({ message: 'Internal server error' }, { status: 500 }),
+ })
+
+ customRender(<DestinationRow destinationId={DESTINATION_ID} />)
+
+ expect(await screen.findByText('Failed to retrieve pipeline information')).toBeInTheDocument()
+ })
+})
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
index 3058ef4e948..964d8025381 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
@@ -18,6 +18,7 @@ import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { DeleteDestination } from './DeleteDestination'
import { PipelineStatus } from './PipelineStatus'
import { PipelineStatusName, STATUS_REFRESH_FREQUENCY_MS } from './Replication.constants'
+import { getFormattedLagValue } from './ReplicationPipelineStatus/ReplicationPipelineStatus.utils'
import { RowMenu } from './RowMenu'
import { UpdateVersionModal } from './UpdateVersionModal'
import { useDestinationInformation } from './useDestinationInformation'
@@ -76,12 +77,23 @@ export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
const { mutateAsync: deleteDestinationPipeline } = useDeleteDestinationPipelineMutation({})
// Fetch table-level replication status to surface errors in list view
- const { data: replicationStatusData } = useReplicationPipelineReplicationStatusQuery(
+ const {
+ data: replicationStatusData,
+ isPending: isReplicationStatusLoading,
+ isError: isReplicationStatusError,
+ } = useReplicationPipelineReplicationStatusQuery(
{ projectRef, pipelineId: pipeline?.id },
{ refetchInterval: STATUS_REFRESH_FREQUENCY_MS }
)
const tableStatuses = replicationStatusData?.table_statuses ?? []
const errorCount = tableStatuses.filter((t) => t.state?.name === 'error').length
+ const applyLag = replicationStatusData?.apply_lag
+ // Show the byte-based slot lag (WAL the destination hasn't confirmed flushing yet). The
+ // time-based flush_lag from pg_stat_replication is routinely NULL for logical slots that are
+ // idle or don't report timed feedback, whereas confirmed_flush_lsn_bytes is always populated.
+ const lagBytes = applyLag?.confirmed_flush_lsn_bytes
+ const lag = getFormattedLagValue('bytes', lagBytes)
+ const isCaughtUp = lagBytes === 0
// Only show errors when pipeline is running (not when stopped or restarting)
const isPipelineStopped = statusName === PipelineStatusName.STOPPED
const isRestarting = requestStatus === PipelineStatusRequestStatus.RestartRequested
@@ -129,7 +141,11 @@ export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
return (
<>
{isPipelineError && (
- <AlertError error={pipelineError} subject="Failed to retrieve pipeline information" />
+ <TableRow>
+ <TableCell colSpan={6}>
+ <AlertError error={pipelineError} subject="Failed to retrieve pipeline information" />
+ </TableCell>
+ </TableRow>
)}
{isPipelineSuccess && (
<TableRow>
@@ -177,7 +193,17 @@ export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
</TableCell>
<TableCell>
- <Minus size={18} className="text-foreground-lighter" />
+ {!pipeline ? (
+ <Minus size={18} className="text-foreground-lighter" />
+ ) : isReplicationStatusLoading ? (
+ <ShimmeringLoader />
+ ) : isReplicationStatusError || !applyLag ? (
+ <Minus size={18} className="text-foreground-lighter" />
+ ) : isCaughtUp ? (
+ <span className="text-foreground-light whitespace-nowrap">Caught up</span>
+ ) : (
+ <span className="text-foreground whitespace-nowrap">{lag.display}</span>
+ )}
</TableCell>
<TableCell>
@@ -196,7 +222,7 @@ export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
<WarningIcon />
</TooltipTrigger>
<TooltipContent side="bottom">
- {errorCount} table{errorCount === 1 ? '' : 's'} encountered replication errors
+ {errorCount} table{errorCount === 1 ? '' : 's'} encountered replication errors.
</TooltipContent>
</Tooltip>
)}
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
index 2da1a1c1025..bb63d34341f 100644
--- a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
@@ -285,7 +285,7 @@ export const Destinations = () => {
<TableHead key="status" className="w-[150px]">
Status
</TableHead>
- <TableHead key="lag" className="w-[80px]">
+ <TableHead key="lag" className="w-[150px]">
Lag
</TableHead>
<TableHead key="publication">Publication</TableHead>
@@ -312,10 +312,10 @@ export const Destinations = () => {
filteredReplicas.length === 0 &&
(hasReplicas || hasDestinations) && (
<TableRow>
- <TableCell colSpan={5}>
+ <TableCell colSpan={6}>
<p>No results found</p>
<p className="text-foreground-light">
- Your search for "{filterString}" did not return any results
+ Your search for "{filterString}" did not return any results.
</p>
</TableCell>
</TableRow>
@@ -337,7 +337,7 @@ export const Destinations = () => {
<h4>Replication keeps your data in sync across systems</h4>
<p className="text-foreground-light text-sm text-balance text-center mt-1">
Deploy read replicas for lower latency and better resource management, or capture
- database changes to external platforms for real-time data pipelines.
+ database changes to external destinations for real-time data pipelines.
</p>
<Button
icon={<Plus />}
diff --git a/apps/studio/components/interfaces/Database/Replication/EnableReplicationCallout.tsx b/apps/studio/components/interfaces/Database/Replication/EnableReplicationCallout.tsx
index 6a3f3d0c17e..1984210deb1 100644
--- a/apps/studio/components/interfaces/Database/Replication/EnableReplicationCallout.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/EnableReplicationCallout.tsx
@@ -57,14 +57,14 @@ const EnableReplicationModal = () => {
<Admonition
type="warning"
className="rounded-none border-0"
- title="Replication is currently in Alpha"
+ title="Replication is currently in alpha"
>
<p className="text-sm leading-normal!">
- This feature is in active development and may change as we gather feedback.
- Availability and behavior can evolve while in Alpha.
+ External replication streams database changes to destinations outside your Supabase
+ project. The feature is in active development and may change as we gather feedback.
</p>
<p className="text-sm leading-normal!">
- Pricing has not been finalized yet. You can enable replication now; we'll announce
+ Pricing is not finalized. You can enable external replication now; we'll announce
pricing later and notify you before any charges apply.
</p>
</Admonition>
@@ -97,7 +97,7 @@ export const EnableReplicationCallout = ({
<h4>Replicate data to external destinations in real time</h4>
<p className="text-sm text-foreground-light">
{hasAccess ? 'Enable external replication' : 'Upgrade to the Pro plan'} to start
- replicating your database changes to {type ?? 'data warehouses and analytics platforms'}
+ replicating your database changes to {type ?? 'data warehouses and analytics platforms'}.
</p>
</div>
<div className="flex gap-x-2">
diff --git a/apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx b/apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx
index f6b43c32a52..c40af9169b7 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReadReplicas/ReadReplicaDetails.tsx
@@ -137,7 +137,7 @@ export const ReadReplicaDetails = () => {
isReactForm={false}
layout="horizontal"
label="Load Balancer URL"
- description="RESTful endpoint for querying and managing your databases through your load balancer"
+ description="RESTful endpoint for querying and managing your databases through your load balancer."
>
<Input readOnly copy className="input-mono" value={loadBalancer?.endpoint} />
</FormItemLayout>
@@ -164,7 +164,7 @@ export const ReadReplicaDetails = () => {
isReactForm={false}
layout="horizontal"
label="Compute Size"
- description="Size of replica will be identical to the primary database"
+ description="Size of replica will be identical to the primary database."
>
<Input readOnly className="input-mono" value={size} />
</FormItemLayout>
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Edges.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Edges.tsx
index 299cced7593..84eebdfbc91 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Edges.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Edges.tsx
@@ -1,19 +1,85 @@
import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath, type EdgeProps } from '@xyflow/react'
import { useParams } from 'common'
-import { Loader2, X } from 'lucide-react'
-import { cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
+import { ArrowRight, Loader2, Square, X, type LucideIcon } from 'lucide-react'
+import { useMemo } from 'react'
+import { cn } from 'ui'
-import { useReplicationLagQuery } from '@/data/read-replicas/replica-lag-query'
-import { formatDatabaseID } from '@/data/read-replicas/replicas.utils'
-import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
+import { getStatusName } from '../Pipeline.utils'
+import { STATUS_REFRESH_FREQUENCY_MS } from '../Replication.constants'
+import { REPLICA_STATUS } from '@/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.constants'
+import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
+import { useReplicationPipelineStatusQuery } from '@/data/replication/pipeline-status-query'
+import { useReplicationPipelinesQuery } from '@/data/replication/pipelines-query'
+import {
+ PipelineStatusRequestStatus,
+ usePipelineRequestStatus,
+} from '@/state/replication-pipeline-request-status'
type EdgeData = {
type: string
identifier: string
+ shiftEdgeEnd: boolean
+}
+
+interface ReplicationState {
isComingUp: boolean
isReplicating: boolean
isFailed: boolean
- shiftEdgeEnd: boolean
+}
+
+interface EdgeVisual {
+ Icon: LucideIcon
+ // CSS color shared by the icon and the connecting line so they always match.
+ color: string
+ opacity: number
+ dashArray: string
+ shouldAnimate: boolean
+ shouldSpin?: boolean
+ isFilled?: boolean
+ strokeWidth?: number
+}
+
+// Picks the icon + line appearance for a replication state. Both the icon and the line are derived
+// here from the same state so they always stay in sync. We deliberately don't surface lag: the line
+// just communicates whether data is moving, stopped, starting, or broken.
+const getEdgeVisual = ({ isComingUp, isReplicating, isFailed }: ReplicationState): EdgeVisual => {
+ if (isFailed) {
+ return {
+ Icon: X,
+ color: 'hsl(var(--destructive-default))',
+ opacity: 1,
+ dashArray: '5 5',
+ shouldAnimate: false,
+ strokeWidth: 4,
+ }
+ }
+ if (isComingUp) {
+ return {
+ Icon: Loader2,
+ color: 'hsl(var(--foreground-light))',
+ opacity: 1,
+ dashArray: '5',
+ shouldAnimate: true,
+ shouldSpin: true,
+ }
+ }
+ if (isReplicating) {
+ return {
+ Icon: ArrowRight,
+ color: 'hsl(var(--brand-default))',
+ opacity: 1,
+ dashArray: '5',
+ shouldAnimate: true,
+ }
+ }
+ return {
+ Icon: Square,
+ color: 'hsl(var(--foreground-lighter))',
+ opacity: 0.5,
+ dashArray: '5 5',
+ shouldAnimate: false,
+ isFilled: true,
+ }
}
export const SmoothstepEdge = ({
@@ -27,12 +93,58 @@ export const SmoothstepEdge = ({
markerEnd,
data,
}: EdgeProps) => {
- const { ref } = useParams()
- const { data: project } = useSelectedProjectQuery()
+ const { ref: projectRef = 'default' } = useParams()
+ const { type, identifier, shiftEdgeEnd } = (data || {}) as EdgeData
+ const isReplica = type === 'replica'
- const { type, identifier, isComingUp, isReplicating, isFailed, shiftEdgeEnd } = (data ||
- {}) as EdgeData
- const formattedId = type === 'replica' ? formatDatabaseID(identifier ?? '') : identifier
+ // Subscribe to the same live status the nodes use, so the line and the node update together.
+ const { data: databases = [] } = useReadReplicasQuery(
+ { projectRef },
+ { enabled: isReplica, refetchInterval: STATUS_REFRESH_FREQUENCY_MS }
+ )
+ const replica = databases.find((x) => x.identifier === identifier)
+
+ const { data: pipelinesData } = useReplicationPipelinesQuery(
+ { projectRef },
+ { enabled: !isReplica }
+ )
+ const pipeline = (pipelinesData?.pipelines ?? []).find(
+ (p) => p.destination_id.toString() === identifier
+ )
+ const { data: pipelineStatusData } = useReplicationPipelineStatusQuery(
+ { projectRef, pipelineId: pipeline?.id },
+ { enabled: !isReplica && !!pipeline?.id, refetchInterval: STATUS_REFRESH_FREQUENCY_MS }
+ )
+ const { getRequestStatus } = usePipelineRequestStatus()
+ const requestStatus = pipeline?.id
+ ? getRequestStatus(pipeline.id)
+ : PipelineStatusRequestStatus.None
+
+ const replicationState = useMemo<ReplicationState>(() => {
+ if (isReplica) {
+ const status = replica?.status
+ return {
+ isReplicating: status === 'ACTIVE_HEALTHY',
+ isComingUp:
+ status !== undefined &&
+ [
+ REPLICA_STATUS.COMING_UP,
+ REPLICA_STATUS.INIT_READ_REPLICA,
+ REPLICA_STATUS.UNKNOWN,
+ ].includes(status),
+ isFailed:
+ status !== undefined &&
+ [REPLICA_STATUS.ACTIVE_UNHEALTHY, REPLICA_STATUS.INIT_FAILED].includes(status),
+ }
+ }
+ const isTransitioning = requestStatus !== PipelineStatusRequestStatus.None
+ const statusName = getStatusName(pipelineStatusData?.status)
+ return {
+ isReplicating: statusName === 'started' && !isTransitioning,
+ isComingUp: isTransitioning || statusName === 'starting' || statusName === 'stopping',
+ isFailed: statusName === 'failed',
+ }
+ }, [isReplica, replica?.status, pipelineStatusData?.status, requestStatus])
const [edgePath, labelX, labelY] = getSmoothStepPath({
sourceX,
@@ -43,69 +155,39 @@ export const SmoothstepEdge = ({
targetPosition,
})
- const {
- data: lagDuration,
- isPending: isLoading,
- isError,
- } = useReplicationLagQuery(
- {
- id: identifier,
- projectRef: ref,
- connectionString: project?.connectionString,
- },
- { enabled: type === 'replica' && isReplicating, refetchInterval: 10000 }
- )
- const lagValue = Number(lagDuration?.toFixed(2) ?? 0).toLocaleString()
- const hasReplicationLagData = data !== undefined && !isError && isReplicating
+ const { Icon, color, opacity, dashArray, shouldAnimate, shouldSpin, isFilled, strokeWidth } =
+ getEdgeVisual(replicationState)
return (
<>
- <BaseEdge path={edgePath} markerEnd={markerEnd} style={style} />
-
- {isFailed && (
- <EdgeLabelRenderer>
- <div
- className={cn('bg-surface-100 p-1 rounded-sm absolute nodrag nopan border')}
- style={{
- transform: `translate(-50%, -50%) translate(${targetX - 30}px,${targetY}px)`,
- }}
- >
- <X size={12} strokeWidth={4} className="text-destructive" />
- </div>
- </EdgeLabelRenderer>
- )}
+ <BaseEdge
+ path={edgePath}
+ markerEnd={markerEnd}
+ style={{
+ ...style,
+ stroke: color,
+ opacity,
+ strokeDasharray: dashArray,
+ animation: shouldAnimate ? 'dashdraw 0.5s linear infinite' : undefined,
+ }}
+ />
- {(isComingUp || hasReplicationLagData) && (
- <EdgeLabelRenderer>
- <Tooltip>
- <TooltipTrigger asChild>
- <div
- className={cn(
- 'bg-surface-100 py-1 rounded-sm absolute nodrag nopan border',
- isLoading || isComingUp ? 'px-1' : 'px-1.5'
- )}
- style={{
- transform: `translate(-50%, -50%) translate(${shiftEdgeEnd ? targetX - 30 : labelX}px,${shiftEdgeEnd ? targetY : labelY}px)`,
- pointerEvents: 'all',
- }}
- >
- {isLoading || isComingUp ? (
- <Loader2 size={12} className="animate-spin" />
- ) : (
- <p className="font-mono text-xs">{lagValue}s</p>
- )}
- </div>
- </TooltipTrigger>
- {!isComingUp && (
- <TooltipContent side="bottom" align="center">
- {isLoading
- ? `Checking replication lag for replica ID: ${formattedId}`
- : `Replication lag (seconds) for replica ID: ${formattedId}`}
- </TooltipContent>
- )}
- </Tooltip>
- </EdgeLabelRenderer>
- )}
+ <EdgeLabelRenderer>
+ <div
+ className="bg-surface-100 p-1 rounded-sm absolute nodrag nopan border"
+ style={{
+ transform: `translate(-50%, -50%) translate(${shiftEdgeEnd ? targetX - 30 : labelX}px,${shiftEdgeEnd ? targetY : labelY}px)`,
+ }}
+ >
+ <Icon
+ size={12}
+ strokeWidth={strokeWidth ?? 2}
+ fill={isFilled ? 'currentColor' : 'none'}
+ className={cn(shouldSpin && 'animate-spin')}
+ style={{ color }}
+ />
+ </div>
+ </EdgeLabelRenderer>
</>
)
}
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Nodes.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Nodes.tsx
index 0de96624b30..95af86ba5be 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Nodes.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/Nodes.tsx
@@ -105,25 +105,23 @@ export const ReplicationNode = ({ id }: { id: string }) => {
<div className="text-sm flex flex-col gap-y-0.5">
<div className="flex items-center">
<p>{type}</p>
- <Tooltip>
- <TooltipTrigger>
- <div className="w-6 h-full flex items-center justify-center">
- <div
- className={cn(
- 'w-2 h-2 rounded-full',
- statusName === 'started'
- ? 'bg-brand'
- : statusName === 'failed'
- ? 'bg-destructive'
- : 'bg-selection'
- )}
- />
- </div>
- </TooltipTrigger>
- <TooltipContent side="bottom" className="capitalize">
- {statusName}
- </TooltipContent>
- </Tooltip>
+ {(statusName === 'started' || statusName === 'failed') && (
+ <Tooltip>
+ <TooltipTrigger>
+ <div className="w-6 h-full flex items-center justify-center">
+ <div
+ className={cn(
+ 'w-2 h-2 rounded-full',
+ statusName === 'started' ? 'bg-brand' : 'bg-destructive'
+ )}
+ />
+ </div>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="capitalize">
+ {statusName}
+ </TooltipContent>
+ </Tooltip>
+ )}
</div>
<p className="text-foreground-light">{destination?.name}</p>
<p className="text-foreground-light">ID: {destination?.id}</p>
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/index.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/index.tsx
index d18ef483d36..f90e8741bff 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/index.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationDiagram/index.tsx
@@ -1,23 +1,17 @@
-import { useQueryClient } from '@tanstack/react-query'
import { Background, ColorMode, ReactFlow, ReactFlowProvider, useReactFlow } from '@xyflow/react'
import { useParams } from 'common'
import { useTheme } from 'next-themes'
import { useEffect, useMemo } from 'react'
-import { getStatusName } from '../Pipeline.utils'
import { PrimaryDatabaseNode, ReadReplicaNode, ReplicationNode } from './Nodes'
import { getDagreGraphLayout } from './ReplicationDiagram.utils'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { useReplicationDestinationsQuery } from '@/data/replication/destinations-query'
-import { replicationKeys } from '@/data/replication/keys'
-import { ReplicationPipelineStatusResponse } from '@/data/replication/pipeline-status-query'
-import { useReplicationPipelinesQuery } from '@/data/replication/pipelines-query'
import { timeout } from '@/lib/helpers'
import '@xyflow/react/dist/style.css'
import { SmoothstepEdge } from './Edges'
-import { REPLICA_STATUS } from '@/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.constants'
export const ReplicationDiagram = () => {
return (
@@ -38,7 +32,6 @@ const edgeTypes = { smoothstep: SmoothstepEdge }
const ReplicationDiagramContent = () => {
const reactFlow = useReactFlow()
const { resolvedTheme } = useTheme()
- const queryClient = useQueryClient()
const { ref: projectRef = 'default' } = useParams()
const { data: databases = [], isSuccess: isSuccessReplicas } = useReadReplicasQuery({
@@ -54,8 +47,6 @@ const ReplicationDiagramContent = () => {
})
const destinations = useMemo(() => data?.destinations ?? [], [data])
- const { data: pipelinesData } = useReplicationPipelinesQuery({ projectRef })
-
const nodes = useMemo(() => {
return [
{ id: projectRef, type: 'primary', data: {}, position: { x: 0, y: 5 } },
@@ -75,68 +66,28 @@ const ReplicationDiagramContent = () => {
}, [destinations, projectRef, readReplicas])
const edges = useMemo(() => {
+ const shiftEdgeEnd = readReplicas.length + destinations.length > 1
+
return [
- ...readReplicas.map((x) => {
- const isReplicating = x.status === 'ACTIVE_HEALTHY'
-
- return {
- id: `${projectRef}-${x.identifier}`,
- source: projectRef,
- target: x.identifier,
- type: 'smoothstep',
- className: 'cursor-default!',
- animated: isReplicating,
- style: {
- opacity: isReplicating ? 1 : 0.4,
- strokeDasharray: isReplicating ? undefined : '5 5',
- },
- data: {
- type: 'replica',
- identifier: x.identifier,
- shiftEdgeEnd: readReplicas.length + destinations.length > 1,
- isReplicating,
- isComingUp: [
- REPLICA_STATUS.COMING_UP,
- REPLICA_STATUS.INIT_READ_REPLICA,
- REPLICA_STATUS.UNKNOWN,
- ].includes(x.status),
- isFailed: [REPLICA_STATUS.ACTIVE_UNHEALTHY, REPLICA_STATUS.INIT_FAILED].includes(
- x.status
- ),
- },
- }
- }),
- ...destinations.map((x) => {
- const pipeline = (pipelinesData?.pipelines ?? []).find((p) => p.destination_id === x.id)
- const pipelineStatus = queryClient.getQueryData(
- replicationKeys.pipelinesStatus(projectRef, pipeline?.id)
- ) as ReplicationPipelineStatusResponse
- const statusName = getStatusName(pipelineStatus?.status)
- const isReplicating = statusName === 'started'
-
- return {
- id: `${projectRef}-${x.id}`,
- source: projectRef,
- target: x.id.toString(),
- type: 'smoothstep',
- className: 'cursor-default!',
- animated: isReplicating,
- style: {
- opacity: isReplicating ? 1 : 0.4,
- strokeDasharray: isReplicating ? undefined : '5 5',
- },
- data: {
- type: 'etl',
- identifier: x.id,
- shiftEdgeEnd: readReplicas.length + destinations.length > 1,
- isReplicating,
- isComingUp: ['starting'].includes(statusName ?? ''),
- isFailed: ['failed'].includes(statusName ?? ''),
- },
- }
- }),
+ ...readReplicas.map((x) => ({
+ id: `${projectRef}-${x.identifier}`,
+ source: projectRef,
+ target: x.identifier,
+ type: 'smoothstep',
+ className: 'cursor-default!',
+ // The edge subscribes to live status itself (see Edges.tsx) so it stays in sync with nodes.
+ data: { type: 'replica', identifier: x.identifier, shiftEdgeEnd },
+ })),
+ ...destinations.map((x) => ({
+ id: `${projectRef}-${x.id}`,
+ source: projectRef,
+ target: x.id.toString(),
+ type: 'smoothstep',
+ className: 'cursor-default!',
+ data: { type: 'etl', identifier: x.id.toString(), shiftEdgeEnd },
+ })),
]
- }, [destinations, pipelinesData?.pipelines, projectRef, queryClient, readReplicas])
+ }, [destinations, projectRef, readReplicas])
const backgroundPatternColor =
resolvedTheme === 'dark' ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.4)'
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
index 915389d6033..d872bb4816f 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
@@ -47,6 +47,7 @@ import { UpdateVersionModal } from '../UpdateVersionModal'
import { SlotLagMetrics } from './ReplicationPipelineStatus.types'
import { getDisabledStateConfig } from './ReplicationPipelineStatus.utils'
import { SlotLagMetricsInline, SlotLagMetricsList } from './SlotLagMetrics'
+import { SlotConnectionIndicator, SlotStatusBadge, SlotStatusLegend } from './SlotStatus'
import { TableReplicationRow } from './TableReplicationRow'
import { AlertError } from '@/components/ui/AlertError'
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
@@ -344,16 +345,19 @@ export const ReplicationPipelineStatus = () => {
{applyLagMetrics && (
<div className="border border-default rounded-lg bg-surface-100 px-4 py-4 space-y-3">
- <div className="flex flex-wrap items-baseline justify-between gap-y-1">
+ <div className="flex flex-wrap items-start justify-between gap-x-4 gap-y-2">
<div>
- <h4 className="text-sm font-semibold text-foreground">Replication lag</h4>
+ <h4 className="text-sm font-semibold text-foreground">Pipeline metrics</h4>
<p className="text-xs text-foreground-light">
- Snapshot of how far this pipeline is trailing behind right now.
+ Live metrics on how this pipeline is doing right now.
</p>
</div>
- <p className="text-xs text-foreground-lighter">
- Updates every {refreshIntervalLabel}
- </p>
+ <div className="flex items-center gap-x-2.5">
+ <SlotConnectionIndicator isActive={applyLagMetrics.active} />
+ <span className="h-3.5 w-px bg-border" />
+ <SlotStatusBadge status={applyLagMetrics.wal_status} />
+ <SlotStatusLegend />
+ </div>
</div>
{isStatusError && (
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.types.ts b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.types.ts
index 02aa0c694a9..568cadb6125 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.types.ts
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.types.ts
@@ -3,15 +3,29 @@ export type RetryPolicy =
| { policy: 'manual_retry' }
| { policy: 'timed_retry'; next_retry: string }
+// WAL availability status reported by Postgres for the replication slot. Unrecognized future
+// values from Postgres are surfaced as 'unknown'; the field is absent when not reported.
+export type SlotWalStatus = 'reserved' | 'extended' | 'unreserved' | 'lost' | 'unknown'
+
export type SlotLagMetrics = {
+ active: boolean
+ wal_status?: SlotWalStatus
restart_lsn_bytes: number
confirmed_flush_lsn_bytes: number
- safe_wal_size_bytes: number
+ // null means Postgres reports unlimited slot WAL retention.
+ safe_wal_size_bytes: number | null
write_lag?: number
flush_lag?: number
+ // Milliseconds since the destination last sent feedback. Present even when write/flush lag are not.
+ reply_time_lag?: number
}
-export type SlotLagMetricKey = keyof SlotLagMetrics
+// Numeric metrics rendered as value tiles (kept separate from the non-numeric slot fields above).
+export type SlotLagMetricKey =
+ | 'confirmed_flush_lsn_bytes'
+ | 'safe_wal_size_bytes'
+ | 'flush_lag'
+ | 'reply_time_lag'
export type TableState = {
table_id: number
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
index 525b86de9ef..68ebf1d39e2 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
@@ -2,13 +2,11 @@ import dayjs from 'dayjs'
import { Badge } from 'ui'
import { getPipelineDisplayState, normalizePipelineStatusName } from '../Pipeline.utils'
-import { RetryPolicy, TableState } from './ReplicationPipelineStatus.types'
+import { RetryPolicy, SlotWalStatus, TableState } from './ReplicationPipelineStatus.types'
import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
import { formatBytes } from '@/lib/helpers'
import { PipelineStatusRequestStatus } from '@/state/replication-pipeline-request-status'
-const numberFormatter = new Intl.NumberFormat()
-
export const getStatusConfig = (state: TableState['state']) => {
switch (state.name) {
case 'queued':
@@ -86,19 +84,19 @@ export const isValidRetryPolicy = (policy: any): policy is RetryPolicy => {
const formatLagBytesValue = (value?: number) => {
if (typeof value !== 'number' || Number.isNaN(value)) {
- return { display: '—', detail: undefined }
+ return { display: 'n/a', detail: undefined }
}
+ // Scale to the most readable unit (e.g. "4 GB"). We intentionally don't surface the raw byte
+ // count as a detail line, since it's unreadable at GB scale (e.g. "4,294,967,296 bytes").
const decimals = value < 1024 ? 0 : value < 1024 * 1024 ? 1 : 2
- const display = formatBytes(value, decimals)
- const detail = `${numberFormatter.format(value)} bytes`
-
- return { display, detail }
+ return { display: formatBytes(value, decimals), detail: undefined }
}
+// Scale to a single readable unit (ms, s, min, h) based on size, with no precise sub-line.
const formatLagDurationValue = (value?: number) => {
if (typeof value !== 'number' || Number.isNaN(value)) {
- return { display: '—', detail: undefined }
+ return { display: 'n/a', detail: undefined }
}
const sign = value < 0 ? '-' : ''
@@ -111,29 +109,148 @@ const formatLagDurationValue = (value?: number) => {
const seconds = duration.asSeconds()
if (seconds < 60) {
- const decimals = seconds >= 10 ? 1 : 2
- return {
- display: `${sign}${seconds.toFixed(decimals)} s`,
- detail: `${numberFormatter.format(value)} ms`,
- }
+ return { display: `${sign}${seconds.toFixed(seconds >= 10 ? 1 : 2)} s`, detail: undefined }
}
const minutes = duration.asMinutes()
if (minutes < 60) {
- const roundedSeconds = Math.round(seconds)
- return {
- display: `${sign}${minutes.toFixed(minutes >= 10 ? 1 : 2)} min`,
- detail: `${numberFormatter.format(roundedSeconds)} s`,
- }
+ return { display: `${sign}${minutes.toFixed(minutes >= 10 ? 1 : 2)} min`, detail: undefined }
}
const hours = duration.asHours()
- const roundedMinutes = Math.round(minutes)
- return {
- display: `${sign}${hours.toFixed(hours >= 10 ? 1 : 2)} h`,
- detail: `${numberFormatter.format(roundedMinutes)} min`,
- }
+ return { display: `${sign}${hours.toFixed(hours >= 10 ? 1 : 2)} h`, detail: undefined }
}
export const getFormattedLagValue = (type: 'bytes' | 'duration', value?: number) =>
type === 'bytes' ? formatLagBytesValue(value) : formatLagDurationValue(value)
+
+export type LagSeverity = 'normal' | 'warning' | 'critical'
+
+type SlotStatusBadgeVariant = 'success' | 'warning' | 'destructive' | 'default'
+
+interface WalStatusMeta {
+ label: string
+ variant: SlotStatusBadgeVariant
+ severity: LagSeverity
+ // Shown in the pipeline-level metrics panel.
+ description: string
+ // Shown in the per-table inline sync view where the slot belongs to a single table.
+ tableDescription: string
+}
+
+// Plain-language meaning, color, and severity for each WAL status Postgres can report for a slot.
+// `variant` drives the badge color; `severity` drives whether the list view raises a warning icon
+// (e.g. "extended" is shown amber as a heads-up but isn't alarming on its own).
+export const WAL_STATUS_META: Record<SlotWalStatus, WalStatusMeta> = {
+ reserved: {
+ label: 'Reserved',
+ variant: 'success',
+ severity: 'normal',
+ description:
+ "Healthy. Your database is keeping the WAL files this pipeline's replication slot needs, and they are within the normal WAL size limit.",
+ tableDescription:
+ "Healthy. Your database is keeping the WAL files this table's replication slot needs, and they are within the normal WAL size limit.",
+ },
+ extended: {
+ label: 'Extended',
+ variant: 'warning',
+ severity: 'normal',
+ description:
+ "Healthy, but growing. This pipeline's replication slot is holding on to more WAL than usual, but your database is still keeping everything it needs.",
+ tableDescription:
+ "Healthy, but growing. This table's replication slot is holding on to more WAL than usual, but your database is still keeping everything it needs.",
+ },
+ unreserved: {
+ label: 'Unreserved',
+ variant: 'warning',
+ severity: 'warning',
+ description:
+ "At risk. Your database is no longer reserving all WAL files this pipeline's replication slot needs. If the pipeline does not catch up soon, those files may be removed.",
+ tableDescription:
+ "At risk. Your database is no longer reserving all WAL files this table's replication slot needs. If the pipeline does not catch up soon, those files may be removed.",
+ },
+ lost: {
+ label: 'Lost',
+ variant: 'destructive',
+ severity: 'critical',
+ description:
+ "Broken. Some WAL files this pipeline's replication slot needs have already been removed. The pipeline can no longer continue from this slot. You can recreate a new pipeline, or set the invalidation behavior to recreate and restart the pipeline.",
+ tableDescription:
+ "Broken. Some WAL files this table's replication slot needs have already been removed. The pipeline can no longer continue from this slot. You can recreate a new pipeline, or set the invalidation behavior to recreate and restart the pipeline.",
+ },
+ unknown: {
+ label: 'Unknown',
+ variant: 'default',
+ severity: 'normal',
+ description:
+ "Unknown. Your database reported an unknown state for this pipeline's replication slot.",
+ tableDescription:
+ "Unknown. Your database reported an unknown state for this table's replication slot.",
+ },
+}
+
+// Postgres reports no WAL status (restart_lsn is null) as "unknown" too, so fall back to it.
+export const getWalStatusMeta = (status?: SlotWalStatus): WalStatusMeta =>
+ WAL_STATUS_META[status ?? 'unknown']
+
+// Legend entries from healthiest to most severe, ending with the unknown/unavailable case.
+export const WAL_STATUS_LEGEND: WalStatusMeta[] = [
+ WAL_STATUS_META.reserved,
+ WAL_STATUS_META.extended,
+ WAL_STATUS_META.unreserved,
+ WAL_STATUS_META.lost,
+ WAL_STATUS_META.unknown,
+]
+
+export const getWalStatusSeverity = (status?: SlotWalStatus): LagSeverity =>
+ getWalStatusMeta(status).severity
+
+// Slot-loss risk from how much of the slot's WAL budget has been consumed, rather than fixed byte
+// thresholds: max_slot_wal_keep_size ≈ retained WAL (restart_lsn_bytes) + remaining headroom
+// (safe_wal_size_bytes), so the consumed fraction is how close the slot is to the "lost" state.
+// A null/absent safe_wal_size_bytes now means unlimited retention, so it carries no budget risk.
+export const SLOT_LOSS_WARNING_RATIO = 0.75
+export const SLOT_LOSS_CRITICAL_RATIO = 0.9
+
+export const getSlotBudgetSeverity = (
+ retainedBytes?: number,
+ safeWalSizeBytes?: number | null
+): LagSeverity => {
+ if (
+ typeof retainedBytes !== 'number' ||
+ typeof safeWalSizeBytes !== 'number' ||
+ !Number.isFinite(retainedBytes) ||
+ !Number.isFinite(safeWalSizeBytes)
+ ) {
+ return 'normal'
+ }
+
+ const total = retainedBytes + safeWalSizeBytes
+ // Nothing retained and no headroom left: nothing to flag (also avoids a 0/0 division). When the
+ // headroom is 0 but WAL is still retained, the ratio is 1 and the slot is correctly critical.
+ if (total <= 0) return 'normal'
+
+ const consumedRatio = retainedBytes / total
+ if (consumedRatio >= SLOT_LOSS_CRITICAL_RATIO) return 'critical'
+ if (consumedRatio >= SLOT_LOSS_WARNING_RATIO) return 'warning'
+ return 'normal'
+}
+
+const SEVERITY_RANK: Record<LagSeverity, number> = { normal: 0, warning: 1, critical: 2 }
+
+const maxSeverity = (a: LagSeverity, b: LagSeverity): LagSeverity =>
+ SEVERITY_RANK[a] >= SEVERITY_RANK[b] ? a : b
+
+// Overall slot health = the worse of the reported WAL status and how close the WAL budget is to
+// running out. Used to color/flag the lag value in the destinations list.
+export const getSlotHealthSeverity = (slot?: {
+ restart_lsn_bytes?: number
+ safe_wal_size_bytes?: number | null
+ wal_status?: SlotWalStatus
+}): LagSeverity => {
+ if (!slot) return 'normal'
+ return maxSeverity(
+ getWalStatusSeverity(slot.wal_status),
+ getSlotBudgetSeverity(slot.restart_lsn_bytes, slot.safe_wal_size_bytes)
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotLagMetrics.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotLagMetrics.tsx
index 52698112996..cede6f71a1d 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotLagMetrics.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotLagMetrics.tsx
@@ -1,38 +1,64 @@
+import dayjs from 'dayjs'
import { Info } from 'lucide-react'
+import { type ReactNode } from 'react'
import { Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import { SlotLagMetricKey, SlotLagMetrics } from './ReplicationPipelineStatus.types'
import { getFormattedLagValue } from './ReplicationPipelineStatus.utils'
+import { SlotConnectionIndicator, SlotStatusBadge } from './SlotStatus'
-const SLOT_LAG_FIELDS: {
+interface SlotLagField {
key: SlotLagMetricKey
label: string
type: 'bytes' | 'duration'
- description: string
-}[] = [
+ description: ReactNode
+ // Friendly label to show in place of a literal "0 bytes" when there's nothing to report.
+ zeroLabel?: string
+ // Friendly label to show when the value is null/absent (e.g. unlimited WAL retention).
+ nullLabel?: string
+ // Optional hover text for the value, derived from the raw value (e.g. an absolute timestamp).
+ getValueTooltip?: (value: number) => string
+}
+
+const SLOT_LAG_FIELDS: SlotLagField[] = [
{
key: 'confirmed_flush_lsn_bytes',
- label: 'WAL Flush lag (size)',
+ label: 'Waiting to sync',
type: 'bytes',
- description:
- 'Bytes between the newest WAL record applied locally and the latest flushed WAL record acknowledged by ETL.',
- },
- {
- key: 'flush_lag',
- label: 'WAL Flush lag (time)',
- type: 'duration',
- description:
- 'Time between flushing recent WAL locally and receiving notification that ETL has written and flushed it.',
+ description: "Changes in your database the pipeline hasn't synced yet.",
+ zeroLabel: 'Caught up',
},
{
key: 'safe_wal_size_bytes',
- label: 'Remaining WAL size',
+ label: 'Room before pausing',
type: 'bytes',
- description:
- 'Bytes still available to write to WAL before this slot risks entering the "lost" state.',
+ description: (
+ <>
+ How much more can pile up before the pipeline has to be set up again. Controlled by the{' '}
+ <code className="text-code-inline">max_slot_wal_keep_size</code> setting.
+ </>
+ ),
+ nullLabel: 'Unlimited',
+ },
+ {
+ key: 'reply_time_lag',
+ label: 'Last check-in',
+ type: 'duration',
+ description: 'Time since the pipeline last reported back to your database.',
+ zeroLabel: 'Just now',
+ // reply_time_lag is "milliseconds ago", so the absolute time is now minus that, in local time.
+ getValueTooltip: (ms) => dayjs().subtract(ms, 'millisecond').format('MMM D, YYYY, h:mm:ss A'),
},
]
+// Resolves a field's value into a display string (+ optional precise detail), honoring the
+// friendly zero/null labels before falling back to the formatted byte/duration value.
+const getFieldDisplay = (field: SlotLagField, value: number | null | undefined) => {
+ if (value == null) return { display: field.nullLabel ?? 'n/a', detail: undefined }
+ if (field.zeroLabel && value === 0) return { display: field.zeroLabel, detail: undefined }
+ return getFormattedLagValue(field.type, value)
+}
+
export const SlotLagMetricsInline = ({
tableName,
metrics,
@@ -45,14 +71,17 @@ export const SlotLagMetricsInline = ({
<span className="truncate font-medium" title={tableName}>
{tableName}
</span>
- <span className="text-foreground-lighter">•</span>
+ <SlotConnectionIndicator isActive={metrics.active} context="table" />
+ <span className="h-3.5 w-px bg-border" />
+ {metrics.wal_status && <SlotStatusBadge status={metrics.wal_status} context="table" />}
+ <span className="h-3.5 w-px bg-border" />
<div className="flex flex-wrap items-center gap-x-3 gap-y-1.5 text-[11px] text-foreground-light">
- {SLOT_LAG_FIELDS.map(({ key, label, type }) => {
- const { display } = getFormattedLagValue(type, metrics[key])
+ {SLOT_LAG_FIELDS.map((field) => {
+ const { display } = getFieldDisplay(field, metrics[field.key])
return (
- <span key={`${tableName}-${key}`} className="flex items-center gap-1">
+ <span key={`${tableName}-${field.key}`} className="flex items-baseline gap-1">
<span className="uppercase tracking-wide text-[10px] text-foreground-lighter">
- {label}
+ {field.label}
</span>
<span className="text-foreground">{display}</span>
</span>
@@ -87,40 +116,54 @@ export const SlotLagMetricsList = ({
return (
<dl className={`grid ${gridClasses}`}>
- {SLOT_LAG_FIELDS.map(({ key, label, type, description }) => (
- <div key={key} className="flex flex-col gap-0.5">
- <dt className={labelClasses}>
- <span className="inline-flex items-center gap-1">
- {label}
- {showMetricInfo && (
+ {SLOT_LAG_FIELDS.map((field) => {
+ const rawValue = metrics[field.key]
+ const { display, detail } = getFieldDisplay(field, rawValue)
+ const valueTooltip =
+ field.getValueTooltip && typeof rawValue === 'number'
+ ? field.getValueTooltip(rawValue)
+ : undefined
+ return (
+ <div key={field.key} className="flex flex-col gap-0.5">
+ <dt className={labelClasses}>
+ <span className="inline-flex items-center gap-1">
+ {field.label}
+ {showMetricInfo && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button
+ type="button"
+ aria-label={`What is ${field.label}`}
+ className="inline-flex h-4 w-4 items-center justify-center rounded-full bg-surface-200 text-foreground-lighter transition-colors hover:bg-surface-300 hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-foreground-lighter"
+ >
+ <Info size={12} />
+ </button>
+ </TooltipTrigger>
+ <TooltipContent side="top" align="start" className="max-w-xs text-xs">
+ {field.description}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </span>
+ </dt>
+ <dd className={`flex flex-col ${valueClasses}`}>
+ {valueTooltip ? (
<Tooltip>
<TooltipTrigger asChild>
- <button
- type="button"
- aria-label={`What is ${label}`}
- className="inline-flex h-4 w-4 items-center justify-center rounded-full bg-surface-200 text-foreground-lighter transition-colors hover:bg-surface-300 hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-foreground-lighter"
- >
- <Info size={12} />
- </button>
+ <span className="w-fit cursor-default">{display}</span>
</TooltipTrigger>
- <TooltipContent side="top" align="start" className="max-w-xs text-xs">
- {description}
+ <TooltipContent side="bottom" className="text-xs">
+ {valueTooltip}
</TooltipContent>
</Tooltip>
- )}
- </span>
- </dt>
- {(() => {
- const { display, detail } = getFormattedLagValue(type, metrics[key])
- return (
- <dd className={`flex flex-col ${valueClasses}`}>
+ ) : (
<span>{display}</span>
- {detail && <span className="text-[11px] text-foreground-lighter">{detail}</span>}
- </dd>
- )
- })()}
- </div>
- ))}
+ )}
+ {detail && <span className="text-[11px] text-foreground-lighter">{detail}</span>}
+ </dd>
+ </div>
+ )
+ })}
</dl>
)
}
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotStatus.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotStatus.tsx
new file mode 100644
index 00000000000..e1d8f0c24d7
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/SlotStatus.tsx
@@ -0,0 +1,135 @@
+import { Info } from 'lucide-react'
+import {
+ Badge,
+ cn,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from 'ui'
+
+import { SlotWalStatus } from './ReplicationPipelineStatus.types'
+import { getWalStatusMeta, WAL_STATUS_LEGEND } from './ReplicationPipelineStatus.utils'
+import { InlineLink } from '@/components/ui/InlineLink'
+import { DOCS_URL } from '@/lib/constants'
+
+export type SlotStatusContext = 'pipeline' | 'table'
+
+const CONNECTION_TEXT: Record<SlotStatusContext, { active: string; inactive: string }> = {
+ pipeline: {
+ active: "This pipeline's replication slot is active and being used right now.",
+ inactive: "This pipeline's replication slot is not active right now.",
+ },
+ table: {
+ active: "This table's replication slot is active and being used right now.",
+ inactive: "This table's replication slot is not active right now.",
+ },
+}
+
+/**
+ * Colored badge for a slot's WAL status, with the plain-language meaning on hover.
+ * Pass `context="table"` in the per-table inline view to show table-specific descriptions.
+ */
+export const SlotStatusBadge = ({
+ status,
+ context = 'pipeline',
+}: {
+ status?: SlotWalStatus
+ context?: SlotStatusContext
+}) => {
+ const meta = getWalStatusMeta(status)
+ const description = context === 'table' ? meta.tableDescription : meta.description
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Badge variant={meta.variant} className="cursor-default">
+ {meta.label}
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="max-w-[260px]">
+ {description}
+ </TooltipContent>
+ </Tooltip>
+ )
+}
+
+/**
+ * Info button opening a legend that explains every possible slot status.
+ */
+export const SlotStatusLegend = () => {
+ return (
+ <Popover>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ aria-label="What do the slot statuses mean?"
+ className="inline-flex h-4 w-4 items-center justify-center rounded-full bg-surface-200 text-foreground-lighter transition-colors hover:bg-surface-300 hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-foreground-lighter"
+ >
+ <Info size={12} />
+ </button>
+ </PopoverTrigger>
+ <PopoverContent side="bottom" align="center" className="w-[26rem] p-0">
+ <div className="px-4 py-3 border-b border-overlay">
+ <p className="text-sm text-foreground">Slot statuses</p>
+ <p className="text-xs text-foreground-light">
+ How safely your database is keeping the changes the pipeline still needs.
+ </p>
+ </div>
+ <ul className="flex flex-col divide-y divide-overlay">
+ {WAL_STATUS_LEGEND.map((meta) => (
+ <li key={meta.label} className="flex items-start gap-x-3 px-4 py-2.5">
+ <div className="flex h-5 w-28 shrink-0 items-center">
+ <Badge variant={meta.variant}>{meta.label}</Badge>
+ </div>
+ <span className="flex-1 text-xs leading-5 text-foreground-light">
+ {meta.description}
+ </span>
+ </li>
+ ))}
+ </ul>
+ <div className="border-t border-overlay px-4 py-2.5">
+ <InlineLink
+ href={`${DOCS_URL}/guides/database/replication/external-replication-monitoring`}
+ className="text-xs text-foreground-light"
+ >
+ Learn more about monitoring replication
+ </InlineLink>
+ </div>
+ </PopoverContent>
+ </Popover>
+ )
+}
+
+/**
+ * Small dot + label indicating whether the slot has a live replication connection.
+ * Pass `context="table"` in the per-table inline view to show table-specific descriptions.
+ */
+export const SlotConnectionIndicator = ({
+ isActive,
+ context = 'pipeline',
+}: {
+ isActive?: boolean
+ context?: SlotStatusContext
+}) => {
+ const text = CONNECTION_TEXT[context]
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span className="flex items-center gap-x-1.5 text-xs text-foreground-light cursor-default">
+ <span
+ className={cn(
+ 'h-1.5 w-1.5 rounded-full shrink-0',
+ isActive ? 'bg-brand' : 'bg-foreground-muted'
+ )}
+ />
+ {isActive ? 'Connected' : 'Not connected'}
+ </span>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="max-w-[260px]">
+ {isActive ? text.active : text.inactive}
+ </TooltipContent>
+ </Tooltip>
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx b/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
index 6360b277b79..984ea9051a8 100644
--- a/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
@@ -9,6 +9,10 @@ import {
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ WarningIcon,
} from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
@@ -18,7 +22,6 @@ import {
PIPELINE_ENABLE_ALLOWED_FROM,
} from './Pipeline.utils'
import { PipelineStatusName } from './Replication.constants'
-import AlertError from '@/components/ui/AlertError'
import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
import { Pipeline } from '@/data/replication/pipelines-query'
import { useRestartPipelineHelper } from '@/data/replication/restart-pipeline-helper'
@@ -134,7 +137,18 @@ export const RowMenu = ({
<div className="flex justify-end items-center space-x-2">
{isLoading && <ShimmeringLoader />}
- {isError && <AlertError error={error} subject="Failed to retrieve pipeline status" />}
+ {isError && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span className="flex items-center" tabIndex={0}>
+ <WarningIcon />
+ </span>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" className="max-w-xs">
+ Couldn't load status{error?.message ? `: ${error.message}` : '.'}
+ </TooltipContent>
+ </Tooltip>
+ )}
<DropdownMenu>
<DropdownMenuTrigger asChild>
diff --git a/packages/api-types/types/platform.d.ts b/packages/api-types/types/platform.d.ts
index 42d08904d7d..3524c4a7095 100644
--- a/packages/api-types/types/platform.d.ts
+++ b/packages/api-types/types/platform.d.ts
@@ -9850,6 +9850,11 @@ export interface components {
ReplicationPipelineReplicationStatusResponse: {
/** @description Stats about apply worker lag */
apply_lag?: {
+ /**
+ * @description Whether the slot currently has an active replication connection.
+ * @example true
+ */
+ active: boolean
/**
* @description Bytes between the current WAL location and the confirmed flush LSN.
* @example 2048
@@ -9860,16 +9865,27 @@ export interface components {
* @example 1200
*/
flush_lag?: number
+ /**
+ * @description Milliseconds elapsed since the walsender last received client feedback. This can be present even when write and flush lag are unavailable.
+ * @example 5000
+ */
+ reply_time_lag?: number
/**
* @description Bytes between the current WAL location and the slot restart LSN.
* @example 1024
*/
restart_lsn_bytes: number
/**
- * @description How many bytes of WAL are still safe to build up before the limit of the slot is reached.
+ * @description How many bytes of WAL are still safe to build up before the limit of the slot is reached. `null` means Postgres reports unlimited slot WAL retention.
* @example 8192
*/
- safe_wal_size_bytes: number
+ safe_wal_size_bytes: number | null
+ /**
+ * @description WAL availability status reported by Postgres for the slot.
+ * @example reserved
+ * @enum {string}
+ */
+ wal_status?: 'reserved' | 'extended' | 'unreserved' | 'lost' | 'unknown'
/**
* @description Write lag expressed in milliseconds.
* @example 1500
@@ -9937,6 +9953,11 @@ export interface components {
table_name: string
/** @description Stats about table sync worker lag */
table_sync_lag?: {
+ /**
+ * @description Whether the slot currently has an active replication connection.
+ * @example true
+ */
+ active: boolean
/**
* @description Bytes between the current WAL location and the confirmed flush LSN.
* @example 2048
@@ -9947,16 +9968,27 @@ export interface components {
* @example 1200
*/
flush_lag?: number
+ /**
+ * @description Milliseconds elapsed since the walsender last received client feedback. This can be present even when write and flush lag are unavailable.
+ * @example 5000
+ */
+ reply_time_lag?: number
/**
* @description Bytes between the current WAL location and the slot restart LSN.
* @example 1024
*/
restart_lsn_bytes: number
/**
- * @description How many bytes of WAL are still safe to build up before the limit of the slot is reached.
+ * @description How many bytes of WAL are still safe to build up before the limit of the slot is reached. `null` means Postgres reports unlimited slot WAL retention.
* @example 8192
*/
- safe_wal_size_bytes: number
+ safe_wal_size_bytes: number | null
+ /**
+ * @description WAL availability status reported by Postgres for the slot.
+ * @example reserved
+ * @enum {string}
+ */
+ wal_status?: 'reserved' | 'extended' | 'unreserved' | 'lost' | 'unknown'
/**
* @description Write lag expressed in milliseconds.
* @example 1500