Embedding a Queryable Analytics Layer Into an Existing Supabase Project
Keep Postgres authoritative while DuckDB and Parquet serve analytics.

Embedding a queryable analytics layer into an existing Supabase project means keeping Postgres as the source of truth while giving analytical queries a columnar engine and governed metric definitions. DuckDB and pre-modeled Parquet datasets provide that separation without a separate warehouse, schema changes, or a new ETL pipeline. The same governed layer can serve embedded dashboards and AI agents without having them query production Postgres.
Why Postgres alone hits a wall when analytics load arrives
The product has users, paying customers have arrived, and a key account asks to see its data inside the app. An investor or a founder looking at how the business did that week soon asks similar questions. Reporting becomes a product requirement. Yet the backend that records every transaction has no analytical layer ready to answer them.
Supabase brings a full PostgreSQL instance together with auth, storage, edge functions, realtime subscriptions, and auto-generated APIs. The business’s ground truth therefore lives in Postgres from the beginning. That is a sound transactional foundation. But analytics needs to aggregate large amounts of data across columns and work out trends over time, while transactions read or update individual records.
The obvious workarounds address only parts of the problem. Exporting data to a legacy BI platform separates reporting from the product, leaves dashboards stale, and requires manual joins to restore user context. Materialized views pre-compute results but age between refreshes. Read replicas protect production traffic from analytical queries, but their row-oriented storage still makes complex aggregations expensive. Isolation alone does not change how data is read.
What the row-versus-column gap actually costs at analytical query time
Postgres keeps the fields of each row together on disk. When an analytical query needs two or three columns out of fifty, a row scan still loads fields that the calculation will discard. The unused fields consume I/O just the same. Read cost therefore grows with row width rather than only with the columns needed for the answer. Columnar storage removes that mismatch by organizing data around the fields analytical queries select.
The penalty grows when the working set exceeds RAM. Row scanning then combines with MVCC checks across millions of tuples, making large aggregations significantly slower. On large aggregation workloads, a full scan and aggregation can take ten or more seconds in PostgreSQL versus under one second in a columnar engine. Those timings are specific to the workloads being compared.
Concurrency makes the cost an application concern. When several dashboard queries run against the same Postgres instance, they compete for its connection pool, and analytical work that runs for a long time keeps those connections in use. Connection spikes that are safe with transactional traffic can put availability at risk under analytical load. Postgres can remain the right application database while being the wrong execution engine for the analysis layered above it.
How pg_duckdb bridges the columnar gap from inside Postgres
The pg_duckdb extension adds DuckDB’s columnar execution inside PostgreSQL, pairing the transactional system of record with an engine designed for analysis. The pattern offers columnar storage, vectorised execution, and sub-second analytical latency without a separate warehouse. Existing application code can remain in place. For analytical workloads, the notes’ benchmark range is ten to one hundred times faster, with zero code changes required.
The extension intercepts analytical queries and routes them through DuckDB while leaving the existing PostgreSQL setup unchanged. For plain PostgreSQL tables, this must be turned on with duckdb.force_execution = true. With Version 1.0, pg_duckdb has moved from an experimental add-on to an option that is ready for production.
For this architecture, analytical execution must run on a dedicated PostgreSQL read replica. The extension must also be installed on the primary because PostgreSQL requires matching extensions when replicas are used. A resource-heavy DuckDB query then affects only the replica. The no-new-infrastructure benefit is avoiding a separate analytical warehouse. Postgres remains authoritative, and adding the engine requires neither a schema migration nor a separate ingestion pipeline.
Pre-modeled Parquet datasets as the governed analytical layer above raw Postgres
If dashboards, reports, and agents each construct SQL against raw tables, they can calculate different answers at columnar speed. One engineer writes SUM(revenue) while another writes SUM(amount_captured). Q2 revenue differs until someone reconciles the calculations manually.
Pre-modeled Parquet datasets move the calculation into a governed layer. Metric definitions are written once, their results stored as governed files, and those datasets served to each consumer that needs them. The requester no longer reconstructs the business logic. A dashboard and an agent can therefore depend on the same definition rather than merely having access to the same underlying tables.
Parquet also fits the execution pattern established by DuckDB. Its columnar format supports sub-second analytical queries, while the files remain portable, inexpensive to store, and readable by compatible tools without a running database server. Governance still depends on their relationship to Postgres. The datasets are derived from it, reconcile to it, and refresh from it, so stored analytical results do not become a competing system of record. The Supabase project gains a modeled read layer rather than a replacement database.
What breaks when AI agents query production Postgres directly
Agents magnify the risks already present when human consumers query raw tables. Direct production access can exhaust the connection pool, bypass or misapply row-level security, and expose tables without the business context needed to interpret them. An agent can produce valid SQL and still answer the wrong question. Missing semantic context is therefore an accuracy problem as well as an access problem.
The accuracy gap can be substantial. The same foundation model can move from roughly fifty percent accuracy on enterprise questions to more than ninety percent when given structured business context. That contrast explains why raw schema access is not enough. Without governed definitions, the agent must guess which fields and calculations to use for the metric it was asked for. Teams deploying agents face that ambiguity now.
The deployment rule follows from those risks. Agents should never have production database credentials in their configuration, and every query an agent makes should go through a gateway. Service accounts need least-privilege scopes, and query controls should allow only approved patterns, with no open SQL. Governed Parquet datasets provide the separate query target. Agents read a governed copy instead of production, and the definitions they receive match those used by dashboards. That separation supports both reliable answers and a narrower security boundary, but it does not replace access controls.
How the Model Context Protocol turns a governed data layer into a shared access surface
The Model Context Protocol allows dashboards and agents to consume the same governed backend without duplicating metric definitions. Pre-modeled datasets become a shared access surface. Scripts, webhooks, and autonomous clients can use that surface as well, extending the analytical layer beyond a dashboard or chat interface.
MCP’s three primitives divide the responsibilities clearly. Tools execute actions such as querying a governed dataset. Resources supply schemas, metric definitions, and governed Parquet files. Prompts provide reusable workflow templates, so an agent does not reinvent the logic for calculating monthly churn. Together, these primitives expose both the available data and the context required to use it.
The July 28, 2026 revision made MCP stateless at the protocol layer by taking out protocol-level session tracking. Requests can go to any server instance behind a plain round-robin load balancer without having to keep session state. That simplifies horizontal scaling under concurrent agent traffic. Remote, serverless clients and servers use Streamable HTTP, while the older SSE transport is legacy.
The same revision tightened authorization through six enhancement proposals, including issuer validation, credential binding, and scope accumulation. Client ID Metadata Documents had arrived in the prior 2025-11-25 revision. Every data-serving endpoint should have OAuth or JWT middleware, and each agent context should be sandboxed against confused-deputy or prompt-injection escalation. Statelessness does not relax the authorization boundary. With those controls, an independent MCP server can expose governed datasets as a background API, decoupled from any single front end.
Observability as the prerequisite that makes the analytical layer trustworthy
A governed dataset inherits problems from the Postgres instance beneath it. Replication lag silently ages its contents, connection exhaustion starves application and analytical queries, and disk pressure can stall or corrupt refreshes. Definitions alone cannot make those results trustworthy. Source health and refresh conditions must be visible before the analytical layer can reliably support decisions.
The Supabase Metrics API exposes roughly two hundred Postgres health and performance metrics in Prometheus exposition format. OpenTelemetry integration supports exporting logs, metrics, and traces to compatible tools. Starting alerts include disk space below twenty percent, active connections above eighty percent of the configured maximum, and replication lag above ten seconds. Idle-in-transaction connections left open for a long time and tail latency above the threshold set for a critical query round out the starting set, which still falls short of a full audit.
For finding problems with queries, pg_stat_statements is the key tool. It records mean execution time, total execution time, and call count for each query, exposing which work degrades under analytical load. Most managed Postgres instances preload it, but each database still requires CREATE EXTENSION to activate it. Supabase Log Drains extend that visibility to external platforms, including Axiom. Available as a paid add-on on Pro, Team, and Enterprise plans, they export logs from Postgres, Auth, Storage, Edge Functions, Realtime, and API Gateway into the team’s monitoring stack.
Picking the five metrics that the analytical layer should own first
Five metrics that help the team make decisions are more useful than thirty poorly chosen metrics. The first governed set should therefore come from the numbers the team actually uses. Reconciliation gives that choice a practical test. ARR should trace to the billing system, cash to the bank, and product usage to the analytics layer. When sales, finance, and product each keep their own version of ARR, executives end up arguing over the arithmetic.
The team must agree on how to calculate Revenue, since revenue and amount_captured differ. CAC needs a single authoritative owner rather than a formula hidden in a spreadsheet or dashboard filter. These are metrics that could each have a clear owner, though the five will not suit every team. The useful starting set depends on which decisions the team makes, while each chosen metric needs a definition that consumers can share and reconcile.
Embedded analytics can also become a paid product. Logistics platforms charge for shipment performance dashboards, HR tech upsells workforce analytics, and fintech places detailed transaction reporting in premium tiers. In those cases, the analytical layer is both a revenue surface and a retention feature, which raises the cost of ambiguity. A definition used in a customer-facing paid dashboard needs the same governed ownership as one used in an executive review.
How a Supabase team adds full analytical capability without a dedicated data team
For a small Supabase team, the practical route is an independent, stateless MCP server exposing pre-modeled datasets that DuckDB queries as governed Parquet files. Those files derive from the existing Postgres instance, keeping the application database authoritative. This pattern provides the analytical access surface that dashboards and agents need for a team without a dedicated data function, while avoiding schema changes, a separate warehouse, and a separately built ETL pipeline.
The no-new-infrastructure premise means avoiding a separately operated data stack, while a server still exposes the datasets and refreshes still connect them to their source. If pg_duckdb supplies in-Postgres execution, its replica constraint also remains. Keeping those duties within this setup makes it easier to run without creating another database with a model of its own.
One person must own the metric definitions. That owner is typically the technical founder or a designated data lead, with final authority over what a metric such as CAC means. The definition belongs in the governed layer. Early standardization, removal of vanity numbers, and a move away from spreadsheet reconciliation keep that burden from growing with the business. A founder asking a question in Slack and an agent summarising weekly performance can then consume identical definitions, even as the number of consumers grows.


