mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## Problem On self-hosted Supabase instances where the `pg_stat_statements` extension is not installed, the Observability Overview page automatically queries the extension on every page load. This produces "relation pg_stat_statements does not exist" errors in Postgres logs for all projects without the extension. Additionally, if a user navigated to the Query Performance page, they received a generic error with no actionable guidance. A secondary issue allowed malformed sort URL params (e.g. `?sort=created_at:asc&order=asc`) to be interpolated directly into SQL ORDER BY clauses. ## Fix - Wrapped the `useSlowQueriesCount` SQL in a `CASE WHEN EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'pg_stat_statements')` guard. The query now returns 0 silently instead of erroring when the extension is absent. - Added a `VALID_SORT_COLUMNS` whitelist in `generateQueryPerformanceSql`. Invalid column names from URL params are rejected and the query falls back to the preset default ORDER BY. - When the Query Performance page fails because `pg_stat_statements` does not exist, a `warning` admonition now appears with "Enable it in Database -> Extensions" guidance instead of a generic destructive error. The Sentry capture is skipped for this expected configuration state. - Extracted `buildSlowQueriesCountSql` as a testable function and added unit tests for both fixes. ## How to test **Extension not installed (self-hosted):** 1. Run a self-hosted Supabase instance without the `pg_stat_statements` extension enabled. 2. Navigate to the Observability Overview page. 3. Check Postgres logs -- no "relation pg_stat_statements does not exist" errors should appear. 4. Navigate to the Query Performance page. 5. Expected: a yellow warning admonition appears saying the extension is not enabled, with a link to Database -> Extensions. No red error. **Extension installed (normal flow):** 1. With `pg_stat_statements` installed, navigate to Observability Overview. 2. Expected: slow queries count loads as normal. 3. Navigate to Query Performance -- data loads as normal. **Invalid sort URL param:** 1. Navigate to `/project/<ref>/observability/query-performance?sort=created_at:asc&order=asc`. 2. Expected: the page loads and falls back to the default sort order (total time descending). No SQL error in logs. **Unit tests:** ``` node apps/studio/node_modules/vitest/dist/cli.js run --no-coverage \ apps/studio/components/interfaces/Observability/useSlowQueriesCount.test.ts \ apps/studio/components/interfaces/QueryPerformance/useQueryPerformanceQuery.test.ts ``` All 28 tests should pass. --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Writing components
Where to create your components
- For components that declare the general structure and layout of a page:
/components/layouts/xxx
- For components that are tightly coupled to a specific interface:
/components/interfaces/xxx
- For components that are meant to be reusable across multiple pages:
/components/ui/xxx
- Note: We're gradually moving files out of the
to-be-cleanedfolder into the respective folders as we refactor
Component structure
- If a component has constants and utility methods that are tightly coupled to itself, keep them close to the component and enclose them in a folder with an
index.tsxas an entry point - Otherwise it can just be a file on its own
- For example:
-
components/ui - SampleComponentA - SampleComponentA.tsx - SampleComponentA.constants.ts - SampleComponentA.utils.ts - SampleComponentA.types.ts - index.ts - SampleComponentB.tsx
-
Template for building components
// Declare the prop types of your component
interface ComponentAProps {
sampleProp: string
}
// Name your component accordingly
const ComponentA = ({ sampleProp }: ComponentAProps) => {
return <div>ComponentA: {sampleProp}</div>
}
export default ComponentA