Skip to content

Chore/add sessions database connections - #48094

Merged
joshenlim merged 14 commits into
masterfrom
chore/add-sessions-database-connections
Jul 21, 2026
Merged

joshenlim merged 14 commits into
masterfrom
chore/add-sessions-database-connections

Conversation

@joshenlim

@joshenlim joshenlim commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

Context

Initial work for Top for Postgres - adds a "Sessions" section under a new Observability segment "Database Connections"
NOTE: All the copywriting and naming might change - not sure what's an ideal title for this
We'll also be iteratively building on top of this UI, adding more actionable signals instead of just information
Changes are featured flagged, off for public

  • This would essentially replace the "View ongoing queries" in the SQL Editor by providing a dedicated UI
    • It checks against pg_stat_activity as per the ongoing queries UI
    • We'll also subsequently deprecate the "Ongoing queries" UI in the SQL editor
    • Defaults into a "live mode" where the data is refreshed every 3 seconds via long-polling
    image
  • Supports filtering by state
    image
  • Users can also terminate queries through here
    image

Summary by CodeRabbit

Release Notes

  • New Features

    • Added an Observability Database Connections page with a live Sessions activity table (state/roles filtering, blocked-by details, session duration, and per-session termination with confirmation).
    • Included a Live/Pause toggle to control automatic refresh (~3 seconds).
  • Enhancements

    • Improved Reports selection filtering: supports optional option quantities, better popover styling, sorted apply behavior, and shows quantity inline.
    • Query performance duration formatting now supports configurable decimal precision.
    • Tooltips can now render richer content (string or React node).

@joshenlim
joshenlim requested a review from a team as a code owner July 20, 2026 09:16
@supabase

supabase Bot commented Jul 20, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@vercel

vercel Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment Jul 21, 2026 8:04am
studio-staging Ready Ready Preview, Comment Jul 21, 2026 8:04am
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 21, 2026 8:04am
design-system Skipped Skipped Jul 21, 2026 8:04am
docs Skipped Skipped Jul 21, 2026 8:04am
ui-library Skipped Skipped Jul 21, 2026 8:04am
zone-www-dot-com Skipped Skipped Jul 21, 2026 8:04am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds PostgreSQL activity querying and a Database Connections observability page with live refresh, URL-synced filters, session metadata, duration and blocking details, query inspection, and confirmed session termination.

Changes

Database Connections Activity

Layer / File(s) Summary
Activity data pipeline
packages/pg-meta/src/sql/studio/database/*, apps/studio/data/database/*
Queries pg_stat_activity, defines typed activity records, filters generated SQL, and exposes a React Query hook with a project-scoped cache key.
Shared activity display contracts
apps/studio/components/interfaces/QueryPerformance/QueryPerformance.utils.ts, apps/studio/components/interfaces/Reports/v2/ReportsSelectFilter.tsx, apps/studio/components/ui/DropdownMenuItemTooltip.tsx, apps/studio/components/interfaces/QueryPerformance/SqlMonacoBlock.tsx
Adds configurable duration precision, sortable filter selections, quantity and popover customization, ReactNode tooltip text, and a read-only rendering note.
Live activity table and termination controls
apps/studio/components/interfaces/Observability/DatabaseConnections/Activity.tsx
Displays session activity with live polling, URL-synced role/state filters, metadata, durations, blocked-by PIDs, query details, and confirmation-backed termination.
Observability page and navigation
apps/studio/pages/project/[ref]/observability/connections.tsx, apps/studio/routes/project/$ref/observability/connections.tsx, apps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.utils.tsx
Registers the Database Connections page, adds live/pause controls and layout wiring, and updates the menu item identifier.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DatabaseConnections
  participant Activity
  participant useDatabaseActivityQuery
  participant PostgreSQL
  DatabaseConnections->>Activity: pass live state
  Activity->>useDatabaseActivityQuery: request activity and filters
  useDatabaseActivityQuery->>PostgreSQL: query pg_stat_activity
  PostgreSQL-->>Activity: return activity rows
  Activity-->>DatabaseConnections: render sessions and controls
Loading

Possibly related PRs

  • supabase/supabase#48089: Refactors Observability menu generation using utilities tied to the Database Connections menu identifier.

Suggested reviewers: ivasilov

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers context and key behavior, but it misses required template sections like CONTRIBUTING confirmation and current behavior. Rewrite it to match the repository template with YES/NO, change type, current behavior, new behavior, and additional context sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: adding Sessions/Database Connections observability UI.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/add-sessions-database-connections

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
apps/studio/components/interfaces/Observability/DatabaseConnections/Activity.tsx (1)

147-151: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

getBadgeVariant has no distinct styling for 'idle in transaction (aborted)'.

This state is arguably more severe than plain 'idle in transaction' (an aborted transaction still holding a lock), yet it falls through to the 'default' variant.

 const getBadgeVariant = (state: DatabaseActivity['state']) => {
   if (state === 'active') return 'success'
-  if (state === 'idle in transaction') return 'warning'
+  if (state === 'idle in transaction' || state === 'idle in transaction (aborted)') return 'warning'
   return 'default'
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/studio/components/interfaces/Observability/DatabaseConnections/Activity.tsx`
around lines 147 - 151, Update getBadgeVariant to explicitly handle the 'idle in
transaction (aborted)' state with a distinct, more severe badge variant than the
warning used for 'idle in transaction', while preserving the existing mappings
for active and other states.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/studio/components/interfaces/Observability/DatabaseConnections/Activity.tsx`:
- Around line 63-66: Rename the useQueryState key in the Activity component’s
stateFilter initialization from “functions” to “state” so the URL parameter
accurately represents the Sessions state filter. Preserve the existing
selectFilterSchema parsing and stateFilter behavior.
- Around line 141-172: Update onConfirmTerminate to remove the empty catch so
abortQuery’s rejection propagates and AlertDialogAction remains open on failure.
Use the query client to invalidate databaseKeys.databaseActivity(projectRef)
after successful termination, alongside the existing mutation behavior, so the
Sessions table refreshes when live updates are paused.
- Around line 41-53: Update getDuration to verify activity.state_change before
calculating idle duration and activity.transaction_start before calculating
idle-in-transaction duration. Return null when either timestamp is absent,
preserving the existing duration calculations for valid timestamps so the UI
displays the placeholder instead of NaNs.

In `@apps/studio/pages/project/`[ref]/observability/connections.tsx:
- Around line 49-53: Update the DatabaseConnections layout in
apps/studio/pages/project/[ref]/observability/connections.tsx:49-53 to use the
title “Database Connections”; update observabilityLayoutTitle in
apps/studio/routes/project/$ref/observability/connections.tsx:5-10 to the same
title; and remove the duplicated NAV_OBSERVABILITY_API_GATEWAY shortcutId from
the connections menu entry in
apps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.utils.tsx:94-102,
unless a dedicated connection shortcut already exists.

---

Nitpick comments:
In
`@apps/studio/components/interfaces/Observability/DatabaseConnections/Activity.tsx`:
- Around line 147-151: Update getBadgeVariant to explicitly handle the 'idle in
transaction (aborted)' state with a distinct, more severe badge variant than the
warning used for 'idle in transaction', while preserving the existing mappings
for active and other states.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a3f41312-a744-4c96-b594-10518abce498

📥 Commits

Reviewing files that changed from the base of the PR and between bf0e84d and c94197c.

⛔ Files ignored due to path filters (1)
  • apps/studio/routeTree.gen.ts is excluded by !**/routeTree.gen.ts
📒 Files selected for processing (10)
  • apps/studio/components/interfaces/Observability/DatabaseConnections/Activity.tsx
  • apps/studio/components/interfaces/QueryPerformance/QueryPerformance.utils.ts
  • apps/studio/components/interfaces/Reports/v2/ReportsSelectFilter.tsx
  • apps/studio/components/layouts/ObservabilityLayout/ObservabilityMenu.utils.tsx
  • apps/studio/data/database/activity-query.ts
  • apps/studio/data/database/keys.ts
  • apps/studio/pages/project/[ref]/observability/connections.tsx
  • apps/studio/routes/project/$ref/observability/connections.tsx
  • packages/pg-meta/src/sql/studio/database/activity.ts
  • packages/pg-meta/src/sql/studio/database/index.ts

@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  237 passed
flaky  2 flaky
skipped  5 skipped

Details

stats  244 tests across 29 suites
duration  4 minutes, 11 seconds
commit  8a956c5

Flaky tests

Features › database.spec.ts › Database › Schema Visualizer › table actions work as expected
Features › table-editor.spec.ts › table editor › copying cell values preserves false and zero

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@kemaldotearth kemaldotearth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few nits I mentioned on Slack:

  • Shall we match up the pause/play button to what we have on unified logs? Basically one pattern instead of two.
  • Loading skeleton for the list. Maybe 3 dummy items at most.
  • Should we use our syntax highlighting like in Query Performance for the query?
  • Did we consciously remove the big metrics?

Otherwise looking fantastic and better terminology with "terminate" rather than "kill"!

@kemaldotearth
kemaldotearth self-requested a review July 21, 2026 07:52
@joshenlim
joshenlim merged commit c7803b8 into master Jul 21, 2026
37 checks passed
@joshenlim
joshenlim deleted the chore/add-sessions-database-connections branch July 21, 2026 08:52
hunleyd added a commit that referenced this pull request Aug 8, 2026
…fomap-entry-for-pitr-archiving-stale' into hunleyd/indata-979-studio-lintinfomap-entry-for-pitr-archiving-stale

* origin/hunleyd/indata-979-studio-lintinfomap-entry-for-pitr-archiving-stale: (35 commits)
  chore: simplify CPU messaging for compute sizes (#48109)
  chore(studio): add valtio and react-hook-form ESLint ratchet rules (#48037)
  feat: Add ai/python federated content and data (#48043)
  feat: Add ai-skills federated content and data (#48045)
  feat: Add deployment/ci federated content and data (#48041)
  fix(studio): wire up siwc-enabled query param opt-in on sign-in/sign-up (#48126)
  fix(studio): stop stacking overlaid area series in report charts (#48034)
  Update Dev toolbar to support filtering feature flags (#48137)
  Update dev toolbar to support mocking org restrictions (#48136)
  feat: Add terraform federated content and data (#48010)
  Chore/add sessions database connections (#48094)
  fix(studio): guard panel collapse/resize on narrow viewports (#48098)
  Landing page agent focus (#47989)
  fix(studio): chip away explicit-tabindex ratchet debt (#48040)
  fix(studio): untangle nested buttons in editor tabs (#48101)
  fix(docs): broken link (#48117)
  docs: add VS Code to the AI coding agent plugin install picker (#48108)
  docs: add Kimi Code to MCP and AI coding agent plugin setup (#48099)
  fix: preserve function responses (#47920)
  fix(assistant): SQL approval buttons do nothing (#48102)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants