Instrumenting User Behavior Directly in Supabase Postgres Without a Separate Event Pipeline

Capture user behavior directly in Postgres before building a separate event pipeline.

· 9 min read
Cover illustration for “Instrumenting User Behavior Directly in Supabase Postgres Without a Separate Event Pipeline”
Supabase Analytics · November 3, 2026 · 9 min read · 1,947 words

Analytics for Supabase teams can begin inside Postgres, using query statistics, triggers, audit tables, and governed views. These mechanisms turn database activity into behavioral data for dashboards and AI agents. A dedicated pipeline becomes necessary when event capture itself strains production writes.

Why teams reach for a separate event pipeline before checking what Postgres already captures

The decision often begins with a founder asking which features users touch, where sessions drop off, and which query paths are hammering the database. A third-party event system seems to offer a way to see what is missing. Before adding that infrastructure, however, the useful question is what the existing database already records. Every INSERT, UPDATE, DELETE, and query execution already goes through Postgres. Much of the signal is already there.

Database operations can reveal content creation, feature activation, subscription changes, and the frequency of user-facing queries. Those signals need definitions before they become product metrics, and database activity should not be mistaken for a complete account of every interaction. Nevertheless, for most zero-to-one teams, native capture and governance mechanisms provide a practical starting point. A separate pipeline should solve a demonstrated constraint identified by examining the available signal.

What Postgres natively records about user behavior, and where that signal lives

The pg_stat_statements extension exposes statement execution statistics, including call counts, mean execution time, and total time. Those measures connect database work to product use when a statement can be associated with a user-facing operation. Frequent calls can show which paths get heavy use, and a rise in execution time can point to a regression after a deploy. This is aggregate data. Its behavioral value comes from knowing which operation the query serves.

Triggers execute defined actions on INSERT, UPDATE, DELETE, or TRUNCATE, allowing mutations to produce records in a dedicated audit table. Such records can include the acting user, changed values, and timestamp, linking a product action to its database effect. Capture takes place within the database transaction, without a separate path for the client to send events. That avoids dependence on an SDK event that can be blocked, dropped, or skipped.

The auto_explain extension adds diagnostic depth by logging an EXPLAIN plan when a query exceeds a configured time threshold. Paired with statement statistics, it connects a slow user-facing operation to its execution plan. Authentication has a ready-made reporting surface as well. Supabase Auth reports show active users, sign-in attempts by type, sign-up volume, password reset requests, and API Gateway Auth Errors grouped by status code. These charts expose authentication behavior without custom event instrumentation.

How to wire triggers and audit tables into a governed behavioral event log

A dedicated audit table and AFTER triggers on tables with behavioral meaning provide a practical starting point for turning mutation records into a durable log. The audit schema needs the table name, operation type, row primary key, old and new values as JSONB, acting user ID, and timestamp. Signups, feature activations, subscription changes, and content creation are suitable examples. A single migration can establish this pattern without changing the existing tables’ columns.

An illustrative table definition is CREATE TABLE user_events (table_name text, operation_type text, row_primary_key text, old_values jsonb, new_values jsonb, acting_user_id uuid, event_timestamp timestamptz DEFAULT now());. The corresponding trigger shape is CREATE TRIGGER record_behavior AFTER INSERT OR UPDATE OR DELETE ON behavioral_table FOR EACH ROW EXECUTE FUNCTION record_user_event();. These statements illustrate the schema and attachment points only. The placeholder table must be replaced, and the trigger function must be defined to populate the event fields. RLS policies complete the governed capture pattern.

The important design choice is where capture lives. Application-layer emission can be omitted by a code path or background job, whereas a trigger attaches capture to the mutation itself. The audit table has its own indexes, separate from the production table’s read path, but its writes still add synchronous work to the transaction. Small event records keep that cost modest at early scale. Applying Row Level Security to the audit table then limits which consumers may read the resulting history.

Using pg_stat_statements and the Supabase Metrics API to turn query patterns into behavioral signal

Call count indicates how often a query path runs, while rising mean execution time indicates deterioration in that path. A sudden spike in a normally rare query can flag changed behavior after a deploy. The cause still requires interpretation. A polling loop, a missing cache, or a feature that has become popular can all cause an unusual number of queries.

This connects performance observability to product analytics without treating them as interchangeable. Statement statistics show how often queries run and what they cost, while audit events add row-level context to explain what changed. Together, they let a team distinguish a widely used operation from one that consumes disproportionate resources. Both signals can be captured without a separate client capture system. Their usefulness depends on preserving the connection between a query or mutation and its product meaning.

The Supabase Metrics API exposes Postgres performance and health series through a scrape endpoint compatible with monitoring tools, including CPU, IO, WAL, connection counts, and query statistics. Teams can import a prebuilt dashboard JSON with over 200 ready-made charts or use the one-click Grafana Cloud integration in Supabase Dashboard. The API is in beta, so metric names and labels may evolve. It is not available on self-hosted Supabase instances at the time of publication.

Scoping access to behavioral data with Row Level Security and views

RLS policies and purpose-built views must define which events consumers can access and how metrics are calculated. An audit-table policy using auth.uid() = acting_user_id restricts a user’s history to their own events when that policy governs the querying role. That boundary belongs in the database. Application middleware alone should not decide who can see a behavioral record.

A curated view over statement statistics can show the top query paths by call count or user-facing operations that are slow, without letting every consumer read raw query text. Metric views over the audit table can encode agreed definitions of activation or adoption. Without that agreement, two engineers can produce different activation counts by filtering on created_at and event_timestamp. A shared view makes the choice explicit.

Supabase Reports in Studio supplies filterable dashboards for database connections, API request volumes, response errors, and authentication events. Which charts are available depends on the plan, from Free through Enterprise. This is a read surface over existing signals. Custom behavioral metrics need the same discipline. A dashboard, Slack report, and AI agent should derive an answer from one shared definition.

Why letting AI agents query production Postgres directly defeats the purpose of native instrumentation

Once governed views are in place, agents should stay within the boundaries those views set. An agent with unrestricted production access can query tables outside the agreed metric definitions and, with an incorrectly scoped role, bypass RLS. The security of the behavioral log depends on the access path used to reach it.

Even read-only queries can put a strain on resources. Agents act autonomously and can chain many queries, drawing on connection-pool capacity in patterns that are difficult to predict. Analytical joins add work to the same instance that serves application traffic. An active connection count approaching max_connections is an observable warning. Giving an agent permission to read is therefore not equivalent to giving it a safe analytical surface.

The Supabase MCP Server demonstrates a narrower pattern through its query_logs tool, which supports read-only SQL on up to 24 hours of logs per request. That scoped log access keeps the coding agent away from the production instance. For behavioral analytics, the corresponding recommendation is a governed copy, such as pre-calculated metrics or a read replica with RLS enforced. Agents consume that analytical surface rather than the production tables that generate the events.

Connecting Supabase instrumentation to an MCP-accessible analytical layer

For teams asking how to get analytics and dashboards for a Supabase project, the next architectural step is a shared analytical interface over governed datasets. Pre-calculated, versioned datasets can be exposed through a single MCP server for dashboards and agents. This separates the metric definition from the consumer. Both can use the same result without generating their own interpretation of the production audit table.

Daily active users, feature adoption rate, and session depth are examples of metrics that can be modeled from the behavioral log, provided its events support those definitions. Pre-calculating them into governed Parquet datasets removes production audit-table queries from the agent’s request path. It does not remove the need to define the metrics carefully. The query_logs tool illustrates scoped access at the log layer, while a governed API extends the principle to modeled behavioral data.

Supabase’s OpenTelemetry integration allows logs, metrics, and traces to be exported to Datadog, Honeycomb, Grafana, or another compatible observability tool. This keeps the observability connection vendor-agnostic. Tool selection can therefore turn on concrete criteria, including supported signals, shared metric definitions, access controls, and separation from production query load.

The objection that Postgres-native instrumentation cannot scale, and where it actually breaks

The strongest objection is resource contention, and it is legitimate. Complex joins and aggregations over a large audit table can consume CPU and IO needed by production traffic. Audit writes also share the production instance’s resources. Separate indexes do not eliminate that competition. Synchronous capture and unrestricted analytical reads on the same instance will eventually hit its limits.

The first distinction is between reading events and recording them. A read replica or pre-calculated dataset moves consumer queries away from production, so the database still handles trigger-based capture but no longer runs repeated analytical joins. The Metrics API supplies observable indicators, including CPU, IO, WAL, and connection counts. These signals make the constraint concrete rather than tying the decision to an arbitrary event count.

Capture has a separate breaking point. A dedicated pipeline, such as Kafka, a CDC connector, or a dedicated event store, becomes necessary when event volume exceeds what synchronous trigger writes can absorb without adding unacceptable write-path latency. Moving analytical reads elsewhere cannot solve that problem. The distinction is decisive because read contention calls for a separate read path, while capture contention can justify a separate pipeline. Most zero-to-one teams are unlikely to reach the latter threshold first.

The minimum viable instrumentation setup and the order to build it

Supabase Reports in Studio provides a practical starting point before any migration. Its charts of authentication behavior, API request patterns, and database health show the baseline the team already has. Reports is available on Free, Pro, Team, and Enterprise plans, with time ranges and chart availability varying by plan. That baseline helps separate an unanswered product question from a signal that simply has not been examined.

The first implementation step is to confirm that pg_stat_statements is active, as it is by default on Supabase Cloud. Add auto_explain with a threshold tied to the team’s SLO, then review query call counts and mean execution times weekly. This establishes a query-level picture of use and degradation. It also shows which operations need more detail about user behavior.

The second step is a migration that creates the audit table, applies RLS policies, and attaches AFTER triggers to selected behavioral tables. Signups, feature activations, and billing events are candidate mutations. The third step is to define metric views for daily active users, feature adoption, or retention cohort membership and expose them through a governed read path. Access must preserve the audit layer’s RLS boundaries. Dashboards and reports then consume agreed definitions that unify their separate SQL interpretations.

The Metrics API can connect database observability to Grafana, Datadog, or a custom dashboard. When agent access is needed, an MCP server can expose the governed analytical copy and pre-calculated datasets built from those definitions.

More in Supabase Analytics