Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/docs/content/guides/ai-tools/byo-mcp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ allow_dynamic_registration = true

### Step 2: Create the MCP server

The fastest path is the [MCP Server block](/library/docs/headless/mcp-server) in the Supabase Library. It installs an Edge Function with the middleware already wired, a `whoami` tool, and a small tool registry to extend:
The fastest path is the [MCP Server block](/library/docs/headless/mcp) in the Supabase Library. It installs an Edge Function with the middleware already wired, a `whoami` tool, and a small tool registry to extend:

```bash
npx shadcn@latest add https://supabase.com/library/r/mcp-server.json
npx shadcn@latest add https://supabase.com/library/r/mcp.json
```

To write the function yourself, start with a table for the tools to work on. Create it with RLS so each user only sees their own rows; the `user_id` default means inserts don't need to pass it. Save this as a migration with `supabase migration new create_todos` and paste it into the generated file:
Expand Down Expand Up @@ -380,7 +380,7 @@ Both examples in this guide are in the `supabase/supabase` repository, ready to

## Resources

- [MCP Server block](/library/docs/headless/mcp-server) and [Headless App block](/library/docs/tanstack/headless-app) in the Supabase Library
- [MCP Server block](/library/docs/headless/mcp) and [Headless App block](/library/docs/tanstack/headless-app) in the Supabase Library
- [`@supabase/server` reference](/docs/reference/server/introduction)
- [MCP authentication with Supabase Auth](/docs/guides/auth/oauth-server/mcp-authentication)
- [OAuth 2.1 server](/docs/guides/auth/oauth-server)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ We can combine Hugging Face with [Supabase Storage](/storage) and [Database Webh
- Create a `caption` column of type `text`.
- Regenerate TypeScript types to include new `image_caption` table.
- Deploy the function to Supabase: `supabase functions deploy huggingface-image-captioning`.
- Create the Database Webhook in the [Supabase Dashboard](/dashboard/project/_/database/hooks) to trigger the `huggingface-image-captioning` function anytime a record is added to the `storage.objects` table.
- Create the Database Webhook in the [Supabase Dashboard](/dashboard/project/_/integrations/webhooks/overview) to trigger the `huggingface-image-captioning` function anytime a record is added to the `storage.objects` table.

## Generate TypeScript types

Expand Down
13 changes: 13 additions & 0 deletions apps/docs/content/guides/api/rest/postgrest-error-codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ Here's the text formatted as a proper markdown table:
| 42501 | if authenticated 403, else 401 | insufficient privileges |
| other | 400 | |

<Admonition type="note">

Some codes in this table are triggered by platform conditions rather than application code. Seeing them in high volume usually points to an infrastructure event rather than a bug in your queries:

- **25006** — The database has entered read-only mode due to disk quota. See [Read-only mode](/docs/guides/platform/database-size#read-only-mode) for causes and recovery steps.
- **53100** — Disk is full. Supabase emits this alongside 25006 during severe disk exhaustion.
- **53300** — Too many connections. The connection pool has reached its limit; check your [connection pool settings](/docs/guides/database/connection-management).
- **57P03** — The database cannot accept connections, typically during a restart or failover.

When you see these codes in volume, check the [Database dashboard](/dashboard/project/_/observability/database) before debugging application code.

</Admonition>

## API level errors

### Connection errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Deno.serve(
)
```

The [MCP Server block](/library/docs/headless/mcp-server) in the Supabase Library packages this as an installable Edge Function, and the [OAuth Consent block](/library/docs/nextjs/oauth-consent) provides the consent screen. See [Deploy MCP servers](/docs/guides/ai-tools/byo-mcp) for the full setup.
The [MCP Server block](/library/docs/headless/mcp) in the Supabase Library packages this as an installable Edge Function, and the [OAuth Consent block](/library/docs/nextjs/oauth-consent) provides the consent screen. See [Deploy MCP servers](/docs/guides/ai-tools/byo-mcp) for the full setup.

<Admonition type="note">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Follow [Set up Pipelines](/docs/guides/database/replication/pipelines#setup-over

Optionally adjust [destination settings](#destination-settings) and [table partitioning and clustering](#table-partitioning-and-clustering) before creation.

Click **Create and start pipeline** and complete the validation and cost confirmations.
Click **Start pipeline** to validate the destination. Review the cost estimate, then click **Create and start pipeline**.

Supabase Pipelines charges and Google Cloud charges are separate. BigQuery can charge for Storage Write API ingestion, storage, and the compute used to apply CDC changes. See [BigQuery CDC pricing](https://cloud.google.com/bigquery/docs/change-data-capture#CDC_pricing).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,61 @@ sidebar_label: 'ClickHouse'

The ClickHouse destination is in private alpha and available only to approved organizations. [Request access](/go/supabase-pipelines-new-destinations) before following this guide.

Replicate Postgres changes to [ClickHouse](https://clickhouse.com/) as current-state tables or an append-only history. [Choose a table engine](#choose-a-table-engine), [prepare resources](#prepare-clickhouse-resources), then [configure the destination](#configure-clickhouse-as-a-destination).
[ClickHouse](https://clickhouse.com/) is a database for analytics. Supabase Pipelines replicates Postgres tables to ClickHouse as either current-state tables or an append-only history of changes.

To replicate data to ClickHouse:

1. [Choose a table engine](#choose-a-table-engine) and check the [source table requirements](#source-table-requirements).
2. [Prepare a database, user, and HTTPS endpoint](#prepare-clickhouse-resources) in ClickHouse.
3. [Configure the ClickHouse destination](#configure-clickhouse-as-a-destination) in the Dashboard.
4. [Query the replicated data](#query-replicated-data) in ClickHouse.

## Source table requirements

`ReplacingMergeTree` requires a source primary key. `MergeTree` can replicate insert-only tables without one. Include all primary-key columns in the publication when the table has a key.
The source table requirements depend on the selected table engine and the operations in the Postgres publication. `ReplacingMergeTree` requires a source primary key. `MergeTree` can replicate insert-only tables without one. If a table has a primary key, include all its key columns in the publication.

Check the [replica-identity and array requirements](#replica-identity-and-arrays) for your source tables.

### Choose a table engine

The table engine controls how ClickHouse represents changes. It is selected for the entire destination.

Choose the engine before creating the pipeline. Changing **Table engine** later does not convert existing destination tables; writes fail if their engine differs from the configured one. Restore the previous setting to resume using those tables.
The table engine determines how ClickHouse stores and queries replicated changes. Choose one engine for the entire destination:

| Engine | Data model and query pattern |
| -------------------- | ------------------------------------------------------------------------------------------------ |
| `ReplacingMergeTree` | Current-state tables. Requires a primary key. Query the generated `__current` view. |
| `MergeTree` | Append-only CDC history. A primary key is optional for insert-only tables. Query the base table. |

Updating a source primary-key value removes the old key from the current-state view and writes the row under its new key. Changing the primary-key definition is a separate [schema change](#schema-change-support).
Choose the engine before creating the pipeline. Changing **Table engine** later does not convert existing destination tables. Writes fail if their engine differs from the configured one. Restore the previous setting to resume writing to those tables.

With `ReplacingMergeTree`, changing a source primary-key value removes the old key from the current-state view and writes the row under its new key. Changing which columns make up the primary key is a separate [schema change](#schema-change-support).

## Prepare ClickHouse resources

Before creating the destination:
Managed Pipelines run in AWS `eu-central-1` (Frankfurt). When creating your ClickHouse service, choose a nearby region to [reduce replication latency](/docs/guides/database/replication/pipelines#region). Then prepare these resources in ClickHouse before creating the destination:

1. Create or choose a ClickHouse database for the replicated tables.
2. Create a dedicated ClickHouse user for Pipelines.
3. Grant the user access to the target database. Pipelines must be able to:
1. Create an empty database for the replicated tables. In ClickHouse Cloud, open your service's **SQL console** and run `create database if not exists pipelines;`, replacing `pipelines` if you prefer another name. Pipelines creates and manages the tables and, for `ReplacingMergeTree`, the current-state views. Do not create or alter these objects yourself.
2. Create a dedicated database user for Pipelines and grant it access to that database. In ClickHouse Cloud, create this user in the **SQL console**; the organization's **Users and roles** page manages console members. The database user must be able to:
- Query `system.databases`, `system.tables`, and `system.columns`
- Create, alter, truncate, and drop tables
- Create and drop views when using `ReplacingMergeTree`
- Insert rows into managed tables
4. Copy the database's HTTPS endpoint, including its port when required. Pipelines rejects HTTP endpoints and private or internal hostnames.

Keep the database otherwise empty. Pipelines manages the replicated tables and current-state views. Don't pre-create or manually alter those objects.
3. Copy the public HTTPS endpoint for your ClickHouse server. In ClickHouse Cloud, click **Connect** and select **HTTPS** to find it. Include the port if your endpoint requires one. Pipelines cannot connect to HTTP endpoints or private and internal hostnames.

The default `ReplacingMergeTree` engine requires ClickHouse 23.5 or later. The `MergeTree` event-log engine does not have this minimum-version requirement.
For `ReplacingMergeTree`, the ClickHouse server must run version 23.5 or later. `MergeTree` does not have this minimum-version requirement.

## Configure ClickHouse as a destination

Follow [Set up Pipelines](/docs/guides/database/replication/pipelines#setup-overview) and select **ClickHouse**. Enter these destination settings:

| Field | Value |
| ---------------- | -------------------------------------------------------------------------- |
| **URL** | Public HTTPS endpoint, including its port when required |
| **User** | Dedicated ClickHouse user |
| **Password** | User's password, if required |
| **Database** | Existing target database |
| **Table engine** | `replacing_merge_tree` for current state or `merge_tree` for event history |
Follow [Set up Pipelines](/docs/guides/database/replication/pipelines#setup-overview). When prompted to choose a destination, select **ClickHouse** and enter the following settings:

Click **Create and start pipeline** and complete the validation and cost confirmations.
| Field | Value |
| ------------------ | ----------------------------------------------------------------------- |
| **HTTPS endpoint** | Public HTTPS endpoint, including its port when required |
| **User** | Your dedicated database user, such as `pipelines_user` |
| **Password** | That user's password, if set |
| **Database** | Destination database, such as `pipelines` |
| **Table engine** | `ReplacingMergeTree` for current state or `MergeTree` for event history |

Place ClickHouse near the [managed pipeline region](/docs/guides/database/replication/pipelines#region).
Click **Start pipeline** to validate the destination. Review the cost estimate, then click **Create and start pipeline**.

## Query replicated data

Expand All @@ -79,7 +81,7 @@ Postgres schema and table names cannot start or end with `_` or contain `"` or `

### ReplacingMergeTree

`ReplacingMergeTree` is the default and is intended for current-state analytics. Pipelines:
Use the generated `__current` view when you need the latest version of each source row. `ReplacingMergeTree` is the default engine. Pipelines:

- Uses the source primary key as ClickHouse's sorting and deduplication key
- Adds an `_etl_version UInt128` ordering column
Expand All @@ -92,16 +94,16 @@ Query the generated view for the current state:

```sql
select *
from "public_orders__current";
from pipelines."public_orders__current";
```

ClickHouse background merges combine older row versions over time. Until they do, querying the base table without `FINAL` can return multiple versions of the same source row. Use the generated `__current` view for normal current-state queries.
ClickHouse background merges combine older row versions over time. Before a merge, the base table can contain multiple versions of the same source row. The generated view uses `FINAL` to return the current version and excludes deleted rows.

Pipelines does not run `OPTIMIZE ... FINAL CLEANUP`. ClickHouse operators remain responsible for any physical tombstone cleanup required by their storage-retention policy.

### MergeTree

`MergeTree` stores every replicated change as an append-only event. Pipelines adds:
Query the base table when you need the history of inserts, updates, and deletes. `MergeTree` stores each replicated change as an append-only event. Pipelines adds:

- `cdc_operation`, containing `INSERT`, `UPDATE`, or `DELETE`
- `cdc_lsn`, containing the Postgres commit LSN for the change
Expand All @@ -111,7 +113,7 @@ The `cdc_operation`, `cdc_lsn`, and `cdc_tx_ordinal` names are reserved and can'

Inserts and updates append the complete new row. A primary-key value update also appends a `DELETE` for the old key. Deletes append the old row when the source uses `REPLICA IDENTITY FULL`. With primary-key identity, a delete contains the key values; other fields use `NULL` for nullable scalars or placeholders such as zero, empty strings, and empty arrays. Those placeholders are not the deleted row's original values.

Read the base table to analyze the event history. Order source changes by `cdc_lsn` and then `cdc_tx_ordinal`. The old-key delete and new-key update from one primary-key value change share both values, so this pair is not a unique destination-row ID.
Order source changes by `cdc_lsn` and then `cdc_tx_ordinal`. The old-key delete and new-key update from one primary-key value change share both values, so this pair is not a unique destination-row ID.

### Truncates and table restarts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Push notifications are an important part of any mobile app. They allow you to se

## Create the database webhook

Navigate to the [Database Webhooks settings](/dashboard/project/_/database/hooks) in your Supabase Dashboard.
Navigate to the [Database Webhooks settings](/dashboard/project/_/integrations/webhooks/overview) in your Supabase Dashboard.

1. Enable and create a new hook.
1. Conditions to fire webhook: Select the `public.notifications` table and tick the `Insert` event.
Expand Down
35 changes: 35 additions & 0 deletions apps/docs/content/guides/observability/advanced-log-filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,41 @@ limit 100;

Combine predicates with `and`, `or`, and `not`. Select only the fields needed for the investigation. To correlate sources, use an identifier present in both; a shared timestamp alone does not establish that events belong to the same request.

## Filter by Postgres error code [#sqlstate-filtering]

Filter `postgres_logs` by SQLSTATE to surface errors at a specific category rather than by message text. The code lives in `log_attributes['parsed.sql_state_code']`.

To see which error codes are occurring across a time window:

```sql
select
log_attributes['parsed.sql_state_code'] as sqlstate,
count() as occurrences
from logs
where source = 'postgres_logs'
and log_attributes['parsed.sql_state_code'] != ''
group by sqlstate
order by occurrences desc
limit 50;
```

During a platform-level incident (such as the database entering read-only mode), codes like `25006` (`read_only_sql_transaction`) and `53100` (`disk_full`) will dominate the results. To focus on application errors while a platform incident is active, exclude the known platform codes:

```sql
select
timestamp,
log_attributes['parsed.sql_state_code'] as sqlstate,
event_message
from logs
where source = 'postgres_logs'
and log_attributes['parsed.sql_state_code'] not in ('25006', '53100', '57P03')
and log_attributes['parsed.error_severity'] = 'ERROR'
order by timestamp desc
limit 50;
```

SQLSTATE codes starting with `25` or `53` usually indicate platform-level resource events rather than application bugs. See the [PostgREST error codes reference](/docs/guides/api/rest/postgrest-error-codes#database-level-errors) and [Database size guide](/docs/guides/platform/database-size#read-only-mode) for context.

## Query limits [#limit-and-result-row-limitations]

Use an explicit `limit` and narrow time range. The logs query surface rejects `select *` and `count(*)`; list columns and use `count()`. A result limit bounds returned rows, not the time range scanned.
Expand Down
Loading
Loading