Skip to content

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

feat(studio): add Multigres logs collection for HA projects (#46499)

Jordi Enrica7dda67549a2
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/MultigresColumnRender.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/MultigresColumnRender.tsx
new file mode 100644
index 00000000000..71022e17b06
--- /dev/null
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/MultigresColumnRender.tsx
@@ -0,0 +1,34 @@
+import { Column } from 'react-data-grid'
+import { TimestampInfo } from 'ui-patterns/TimestampInfo'
+
+import type { LogData } from '../Logs.types'
+import { parseMultigresEventMessage } from '../Logs.utils'
+import { RowLayout, SeverityFormatter, TextFormatter } from '../LogsFormatters'
+import { defaultRenderCell } from './DefaultPreviewColumnRenderer'
+
+const columns: Column<LogData>[] = [
+ {
+ name: 'multigres-first-column',
+ key: 'multigres-first-column',
+ renderHeaderCell: () => null,
+ renderCell: (props) => {
+ const parsed = parseMultigresEventMessage(props.row.event_message)
+ const level = typeof parsed?.level === 'string' ? parsed.level : undefined
+ const msg = typeof parsed?.msg === 'string' ? parsed.msg : undefined
+
+ if (!level && !msg) {
+ return defaultRenderCell(props)
+ }
+
+ return (
+ <RowLayout>
+ {props.row.timestamp && <TimestampInfo utcTimestamp={props.row.timestamp} />}
+ {level && <SeverityFormatter value={level} />}
+ <TextFormatter className="w-full" value={msg ?? props.row.event_message} />
+ </RowLayout>
+ )
+ },
+ },
+]
+
+export default columns
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx b/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx
index db9895400c8..d53c652d3f7 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogSelection.tsx
@@ -12,8 +12,8 @@ import {
import { CodeBlock } from 'ui-patterns/CodeBlock'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
-import type { LogData, QueryType } from './Logs.types'
-import { apiKey, role as extractRole, jwtAPIKey } from './Logs.utils'
+import type { LogData, PreviewLogData, QueryType } from './Logs.types'
+import { apiKey, role as extractRole, jwtAPIKey, parseMultigresEventMessage } from './Logs.utils'
import DefaultPreviewSelectionRenderer from './LogSelectionRenderers/DefaultPreviewSelectionRenderer'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
@@ -70,6 +70,16 @@ const LogSelection = ({ log, onClose, queryType, isLoading, error }: LogSelectio
return <DefaultPreviewSelectionRenderer log={apiLog} />
+ case 'multigres': {
+ const parsedMultigresMessage = parseMultigresEventMessage(log.event_message)
+ // Spread the log last so its canonical fields (id, timestamp, event_message)
+ // always win over any same-named keys inside the parsed event_message.
+ const multigresLog = (
+ parsedMultigresMessage ? { ...parsedMultigresMessage, ...log } : log
+ ) as PreviewLogData
+ return <DefaultPreviewSelectionRenderer log={multigresLog} />
+ }
+
case 'database':
const hint = log?.metadata?.[0]?.parsed?.[0]?.hint
const detail = log?.metadata?.[0]?.parsed?.[0]?.detail
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx b/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
index d09662119bf..4052f11372d 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogTable.tsx
@@ -24,6 +24,7 @@ import DatabasePostgresColumnRender from './LogColumnRenderers/DatabasePostgresC
import DefaultPreviewColumnRenderer from './LogColumnRenderers/DefaultPreviewColumnRenderer'
import FunctionsEdgeColumnRender from './LogColumnRenderers/FunctionsEdgeColumnRender'
import FunctionsLogsColumnRender from './LogColumnRenderers/FunctionsLogsColumnRender'
+import MultigresColumnRender from './LogColumnRenderers/MultigresColumnRender'
import type { LogData, LogQueryError, QueryType } from './Logs.types'
import {
formatLogsAsCsv,
@@ -265,6 +266,9 @@ export const LogTable = ({
case 'pg_cron':
columns = DatabasePostgresColumnRender
break
+ case 'multigres':
+ columns = MultigresColumnRender
+ break
default:
if (firstRow && isDefaultLogPreviewFormat(firstRow)) {
columns = DefaultPreviewColumnRenderer
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.constants.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.constants.ts
index 5cf09e190c3..4a00919e14b 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.constants.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.constants.ts
@@ -396,6 +396,7 @@ export enum LogsTableName {
PG_UPGRADE = 'pg_upgrade_logs',
PG_CRON = 'pg_cron_logs',
ETL = 'etl_replication_logs',
+ MULTIGRES = 'multigres_logs',
}
export const LOGS_TABLES = {
@@ -412,6 +413,7 @@ export const LOGS_TABLES = {
pg_cron: LogsTableName.POSTGRES,
pgbouncer: LogsTableName.PGBOUNCER,
etl: LogsTableName.ETL,
+ multigres: LogsTableName.MULTIGRES,
}
export const LOGS_SOURCE_DESCRIPTION = {
@@ -429,6 +431,7 @@ export const LOGS_SOURCE_DESCRIPTION = {
[LogsTableName.PG_UPGRADE]: 'Logs generated by the Postgres version upgrade process',
[LogsTableName.PG_CRON]: 'Postgres logs from pg_cron cron jobs',
[LogsTableName.ETL]: 'Logs from the replication process',
+ [LogsTableName.MULTIGRES]: 'Logs from the Multigres high availability service',
}
export const FILTER_OPTIONS: FilterTableSet = {
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts
index 1ce297b8aaa..f29dc87a703 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts
@@ -96,6 +96,7 @@ export type QueryType =
| 'pg_cron'
| 'pgbouncer'
| 'etl'
+ | 'multigres'
export type Mode = 'simple' | 'custom'
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts
index 8023a487d1f..5022103693b 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts
@@ -7,6 +7,7 @@ import {
formatLogsAsCsv,
formatLogsAsJson,
formatLogsAsMarkdown,
+ parseMultigresEventMessage,
} from './Logs.utils'
const createLog = (overrides: Partial<LogData> = {}): LogData => ({
@@ -182,4 +183,40 @@ describe('Logs.utils', () => {
expect(extractEdgeFunctionName('/functions/v1/hello-world-1/')).toBe('hello-world-1')
})
})
+
+ describe('parseMultigresEventMessage', () => {
+ test('parses a JSON object event_message into a plain object', () => {
+ const eventMessage = JSON.stringify({
+ time: '2026-06-02T15:44:52.84043038Z',
+ level: 'ERROR',
+ msg: 'Failed to write heartbeat',
+ error: 'context deadline exceeded',
+ })
+ expect(parseMultigresEventMessage(eventMessage)).toEqual({
+ time: '2026-06-02T15:44:52.84043038Z',
+ level: 'ERROR',
+ msg: 'Failed to write heartbeat',
+ error: 'context deadline exceeded',
+ })
+ })
+
+ test('returns null when event_message is not valid JSON', () => {
+ expect(parseMultigresEventMessage('connection closed')).toBeNull()
+ })
+
+ test('returns null when event_message parses to an array', () => {
+ expect(parseMultigresEventMessage('[1, 2, 3]')).toBeNull()
+ })
+
+ test('returns null when event_message parses to a primitive', () => {
+ expect(parseMultigresEventMessage('42')).toBeNull()
+ expect(parseMultigresEventMessage('"a string"')).toBeNull()
+ })
+
+ test('returns null for non-string input', () => {
+ expect(parseMultigresEventMessage(undefined)).toBeNull()
+ expect(parseMultigresEventMessage(null)).toBeNull()
+ expect(parseMultigresEventMessage(42)).toBeNull()
+ })
+ })
})
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts
index 0636cd65fbf..4c9a90e720a 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts
@@ -303,13 +303,34 @@ export const LOG_TABLE_SQL: Record<LogsTableName, SafeLogSqlFragment> = {
[LogsTableName.PG_UPGRADE]: safeSql`pg_upgrade_logs`,
[LogsTableName.PG_CRON]: safeSql`pg_cron_logs`,
[LogsTableName.ETL]: safeSql`etl_replication_logs`,
+ [LogsTableName.MULTIGRES]: safeSql`multigres_logs`,
}
/**
* SQL query to retrieve only one log
*/
-export const genSingleLogQuery = (table: LogsTableName, id: string): SafeLogSqlFragment =>
- safeSql`select id, timestamp, event_message, metadata from ${LOG_TABLE_SQL[table]} where id = ${analyticsLiteral(id)} limit 1`
+export const genSingleLogQuery = (table: LogsTableName, id: string): SafeLogSqlFragment => {
+ // multigres logs have no metadata column
+ const metadataColumn = table === LogsTableName.MULTIGRES ? safeSql`` : safeSql`, metadata`
+ return safeSql`select id, timestamp, event_message${metadataColumn} from ${LOG_TABLE_SQL[table]} where id = ${analyticsLiteral(id)} limit 1`
+}
+
+/**
+ * Multigres logs store their structured payload as a JSON string in
+ * `event_message`. Parse it into a plain object, returning `null` when the
+ * value is missing, not valid JSON, or not a plain object (e.g. an array).
+ */
+export const parseMultigresEventMessage = (
+ eventMessage: unknown
+): Record<string, unknown> | null => {
+ if (typeof eventMessage !== 'string') return null
+ try {
+ const parsed = JSON.parse(eventMessage)
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null
+ } catch {
+ return null
+ }
+}
/**
* Determine if we should show the user an upgrade prompt while browsing logs
@@ -699,6 +720,8 @@ function getErrorCondition(table: LogsTableName): SafeLogSqlFragment {
return safeSql`metadata.level IN ('error', 'fatal')`
case 'pg_cron_logs':
return safeSql`parsed.error_severity IN ('ERROR', 'FATAL', 'PANIC')`
+ case 'multigres_logs':
+ return safeSql`JSON_VALUE(event_message, '$.level') IN ('ERROR', 'FATAL', 'PANIC')`
default:
return safeSql`false`
}
@@ -716,6 +739,8 @@ function getWarningCondition(table: LogsTableName): SafeLogSqlFragment {
return safeSql`response.status_code >= 400 AND response.status_code < 500`
case 'function_logs':
return safeSql`metadata.level IN ('warning')`
+ case 'multigres_logs':
+ return safeSql`JSON_VALUE(event_message, '$.level') IN ('WARN', 'WARNING')`
default:
return safeSql`false`
}
@@ -830,6 +855,7 @@ const QUERY_TYPE_LABELS: Record<QueryType, string> = {
pg_cron: 'pg_cron',
pgbouncer: 'PgBouncer',
etl: 'ETL',
+ multigres: 'Multigres',
}
const LOG_TABLE_TO_SERVICE_LABEL: Record<LogsTableName, string> = {
@@ -847,6 +873,7 @@ const LOG_TABLE_TO_SERVICE_LABEL: Record<LogsTableName, string> = {
pg_upgrade_logs: 'Postgres upgrade',
pg_cron_logs: 'pg_cron',
etl_replication_logs: 'ETL',
+ multigres_logs: 'Multigres',
}
const isLogsTableName = (value: string): value is LogsTableName =>
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx b/apps/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx
index 0f1f279c725..cda950344e3 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx
@@ -185,6 +185,7 @@ export const SeverityFormatter = ({
)
break
+ case 'WARN':
case 'WARNING':
return (
<Layout className="gap-1">
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx b/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
index 61492a08984..335fa7d4916 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx
@@ -38,6 +38,7 @@ import { DatePickerValue, LogsDatePicker } from './Logs.DatePickers'
import { LogsWarning, LogTemplate } from './Logs.types'
import Table from '@/components/to-be-cleaned/Table'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
+import { useShowMultigresLogs } from '@/hooks/misc/useShowMultigresLogs'
import { DOCS_URL } from '@/lib/constants'
export interface LogsQueryPanelProps {
@@ -98,7 +99,13 @@ const LogsQueryPanel = ({
}, [value.from, value.to, value.text, value.isHelper])
const [open, setOpen] = useState(false)
- const [selectedSchema, setSelectedSchema] = useState(logConstants.schemas[0])
+
+ const showMultigresLogs = useShowMultigresLogs()
+ const schemas = logConstants.schemas.filter(
+ (schema) => schema.reference !== 'multigres_logs' || showMultigresLogs
+ )
+
+ const [selectedSchema, setSelectedSchema] = useState(schemas[0])
return (
<div className="flex items-center border-b bg-surface-100 h-(--header-height)">
@@ -285,7 +292,7 @@ const LogsQueryPanel = ({
<CommandList>
<CommandEmpty>No source found.</CommandEmpty>
<CommandGroup>
- {logConstants.schemas.map((schema) => (
+ {schemas.map((schema) => (
<CommandItem
key={schema.reference}
value={schema.reference}
diff --git a/apps/studio/components/layouts/LogsLayout/LogsSidebarMenuV2.tsx b/apps/studio/components/layouts/LogsLayout/LogsSidebarMenuV2.tsx
index b152f6abb09..b2daa4da0f3 100644
--- a/apps/studio/components/layouts/LogsLayout/LogsSidebarMenuV2.tsx
+++ b/apps/studio/components/layouts/LogsLayout/LogsSidebarMenuV2.tsx
@@ -34,6 +34,7 @@ import { useContentQuery } from '@/data/content/content-query'
import { useReplicationSourcesQuery } from '@/data/replication/sources-query'
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
+import { useShowMultigresLogs } from '@/hooks/misc/useShowMultigresLogs'
export function SidebarCollapsible({
children,
@@ -100,6 +101,7 @@ export function LogsSidebarMenuV2() {
const showETLLogs = enablePgReplicate && (etlData?.sources?.length ?? 0) > 0 && !isETLLoading
const { hasAccess: hasDedicatedPooler } = useCheckEntitlements('dedicated_pooler')
+ const showMultigresLogs = useShowMultigresLogs()
const { data: savedQueriesRes, isPending: savedQueriesLoading } = useContentQuery({
projectRef: ref,
@@ -193,6 +195,14 @@ export function LogsSidebarMenuV2() {
items: [],
}
: null,
+ showMultigresLogs
+ ? {
+ name: 'Multigres',
+ key: 'multigres-logs',
+ url: `/project/${ref}/logs/multigres-logs`,
+ items: [],
+ }
+ : null,
].filter((x) => x !== null)
const OPERATIONAL_COLLECTIONS = IS_PLATFORM
diff --git a/apps/studio/hooks/misc/useShowMultigresLogs.test.ts b/apps/studio/hooks/misc/useShowMultigresLogs.test.ts
new file mode 100644
index 00000000000..27082f99ea1
--- /dev/null
+++ b/apps/studio/hooks/misc/useShowMultigresLogs.test.ts
@@ -0,0 +1,60 @@
+import { renderHook } from '@testing-library/react'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { useShowMultigresLogs } from './useShowMultigresLogs'
+
+const mockUseFlag = vi.fn()
+const mockUseIsHighAvailability = vi.fn()
+
+vi.mock('common', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('common')>()),
+ useFlag: (name: string) => mockUseFlag(name),
+}))
+
+vi.mock('./useSelectedProject', () => ({
+ useIsHighAvailability: () => mockUseIsHighAvailability(),
+}))
+
+describe('useShowMultigresLogs', () => {
+ beforeEach(() => {
+ mockUseFlag.mockReset()
+ mockUseIsHighAvailability.mockReset()
+ })
+
+ it('returns true only when the multigresLogs flag and high availability are both enabled', () => {
+ mockUseFlag.mockReturnValue(true)
+ mockUseIsHighAvailability.mockReturnValue(true)
+
+ const { result } = renderHook(() => useShowMultigresLogs())
+
+ expect(result.current).toBe(true)
+ expect(mockUseFlag).toHaveBeenCalledWith('multigresLogs')
+ })
+
+ it('returns false when the flag is off, even on a high availability project', () => {
+ mockUseFlag.mockReturnValue(false)
+ mockUseIsHighAvailability.mockReturnValue(true)
+
+ const { result } = renderHook(() => useShowMultigresLogs())
+
+ expect(result.current).toBe(false)
+ })
+
+ it('returns false when the project is not high availability, even with the flag on', () => {
+ mockUseFlag.mockReturnValue(true)
+ mockUseIsHighAvailability.mockReturnValue(false)
+
+ const { result } = renderHook(() => useShowMultigresLogs())
+
+ expect(result.current).toBe(false)
+ })
+
+ it('returns false when both the flag and high availability are off', () => {
+ mockUseFlag.mockReturnValue(false)
+ mockUseIsHighAvailability.mockReturnValue(false)
+
+ const { result } = renderHook(() => useShowMultigresLogs())
+
+ expect(result.current).toBe(false)
+ })
+})
diff --git a/apps/studio/hooks/misc/useShowMultigresLogs.ts b/apps/studio/hooks/misc/useShowMultigresLogs.ts
new file mode 100644
index 00000000000..7975cafb22e
--- /dev/null
+++ b/apps/studio/hooks/misc/useShowMultigresLogs.ts
@@ -0,0 +1,24 @@
+import { useFlag } from 'common'
+
+import { useIsHighAvailability } from './useSelectedProject'
+
+/**
+ * Whether to surface the Multigres logs collection (sidebar, page, and Field
+ * Reference source).
+ *
+ * Gated on both:
+ * - the `multigresLogs` feature flag, so rollout is decoupled from HA status
+ * and the feature ships dark until explicitly enabled, and
+ * - the project's `high_availability` flag, since Multigres only runs on HA
+ * projects.
+ *
+ * Note: `high_availability` is an existing product feature that predates
+ * Multigres, so the flag is required to avoid showing a broken collection to
+ * existing HA projects that don't have a `multigres_logs` table.
+ */
+export const useShowMultigresLogs = () => {
+ const multigresLogsEnabled = useFlag('multigresLogs')
+ const isHighAvailability = useIsHighAvailability()
+
+ return multigresLogsEnabled && isHighAvailability
+}
diff --git a/apps/studio/pages/project/[ref]/logs/multigres-logs.tsx b/apps/studio/pages/project/[ref]/logs/multigres-logs.tsx
new file mode 100644
index 00000000000..768b40b4a37
--- /dev/null
+++ b/apps/studio/pages/project/[ref]/logs/multigres-logs.tsx
@@ -0,0 +1,28 @@
+import { useParams } from 'common'
+
+import { LogsTableName } from '@/components/interfaces/Settings/Logs/Logs.constants'
+import { LogsPreviewer } from '@/components/interfaces/Settings/Logs/LogsPreviewer'
+import DefaultLayout from '@/components/layouts/DefaultLayout'
+import LogsLayout from '@/components/layouts/LogsLayout/LogsLayout'
+import type { NextPageWithLayout } from '@/types'
+
+export const LogPage: NextPageWithLayout = () => {
+ const { ref } = useParams()
+
+ return (
+ <LogsPreviewer
+ condensedLayout
+ queryType="multigres"
+ projectRef={ref as string}
+ tableName={LogsTableName.MULTIGRES}
+ />
+ )
+}
+
+LogPage.getLayout = (page) => (
+ <DefaultLayout>
+ <LogsLayout title="Multigres Logs">{page}</LogsLayout>
+ </DefaultLayout>
+)
+
+export default LogPage
diff --git a/packages/shared-data/log-constants.ts b/packages/shared-data/log-constants.ts
index 6ed5d53175c..a7c214981fb 100644
--- a/packages/shared-data/log-constants.ts
+++ b/packages/shared-data/log-constants.ts
@@ -12,6 +12,7 @@ type LogTable =
| 'pgbouncer_logs'
| 'pg_cron_logs'
| 'pg_upgrade_logs'
+ | 'multigres_logs'
type LogSchema = {
name: string
@@ -324,6 +325,23 @@ const schemas: LogSchema[] = [
{ path: 'timestamp', type: 'datetime' },
],
},
+ {
+ name: 'Multigres',
+ reference: 'multigres_logs',
+ fields: [
+ { path: 'cluster', type: 'string' },
+ { path: 'component', type: 'string' },
+ { path: 'event_message', type: 'string' },
+ { path: 'id', type: 'string' },
+ { path: 'namespace', type: 'string' },
+ { path: 'node_name', type: 'string' },
+ { path: 'pod_name', type: 'string' },
+ { path: 'project', type: 'string' },
+ { path: 'region', type: 'string' },
+ { path: 'stack', type: 'string' },
+ { path: 'timestamp', type: 'datetime' },
+ ],
+ },
]
export default {