# PostgreSQL Analytics with Bonnard

> Connect Bonnard to PostgreSQL, including Supabase, Neon, and RDS, and ship governed metrics to AI agents, embedded charts, dashboards, and your product via MCP.

Bonnard turns your PostgreSQL database into a governed PostgreSQL analytics backend. If your application data lives in Postgres (including Supabase, Neon, and RDS), Bonnard connects directly and exposes your metrics through MCP, React SDK, REST API, and markdown dashboards.

## How does Bonnard connect to PostgreSQL?

Add PostgreSQL as a datasource in your Bonnard project. Define the connection in your `datasources.yml`:

```yaml
# datasources.yml
datasources:
  - name: postgres_db
    type: postgres
    host: db.example.com
    port: 5432
    database: app_production
    username: bonnard_readonly
    password: ${POSTGRES_PASSWORD}
    schema: public
    ssl: true
```

Then run:

```bash
bon datasource add postgres_db
bon deploy
```

Bonnard connects over standard Postgres wire protocol, introspects your schema, and deploys your [semantic layer](/semantic-layer). Works with any Postgres-compatible database: Amazon RDS, Aurora, Supabase, Neon, AlloyDB, CockroachDB, and TimescaleDB.

## What do you get?

Once connected, your PostgreSQL data is available through four surfaces:

**[MCP](/glossary/mcp) server.** Run `bon mcp` and your AI agents (Claude, ChatGPT, Cursor) query governed Postgres metrics with row-level security. Generate publishable keys per tenant for customer-facing [agentic analytics](/agentic-analytics).

**React SDK.** Drop `BarChart`, `LineChart`, and `BigValue` components into your product. Every chart queries your Postgres database through the semantic layer with multi-tenant access controls applied automatically.

**REST API.** Query metrics programmatically from any language or platform. Type-safe queries with the TypeScript SDK or raw HTTP from anywhere.

**Markdown dashboards.** Author dashboards in markdown, deploy with `bon deploy`, and share governed views with your team or customers.

## How does Bonnard compare to querying Postgres directly?

| Capability | Postgres direct | Bonnard + PostgreSQL |
|------------|----------------|---------------------|
| Metric definitions | SQL views, application code | YAML semantic layer (version-controlled) |
| AI agent access | None | MCP server with publishable keys |
| Embedded analytics | Build from scratch | React SDK with multi-tenant auth |
| Dashboards | External tools (Metabase, Grafana) | Markdown dashboards, deployed via CLI |
| Multi-tenancy | Row-level security (manual) | Publishable keys + automatic row filters |
| Pre-aggregation | Materialized views (manual refresh) | Automatic pre-aggregation cache |
| Access control | Postgres roles | YAML-defined RBAC + audit logging |
| Deployment | Migration scripts | `bon deploy` (no restart, no SSH) |

## Works with Supabase and Neon

If you're building on Supabase or Neon, Bonnard connects to your database the same way it connects to any Postgres instance. Use your connection string from the Supabase or Neon dashboard, set `ssl: true`, and deploy. Your application database becomes a governed analytics backend without changing your existing setup.

## FAQ

**Does Bonnard support PostgreSQL?**

Yes. PostgreSQL is a first-class Bonnard datasource. Any Postgres-compatible database works: self-hosted, RDS, Aurora, Supabase, Neon, AlloyDB, CockroachDB, TimescaleDB.

**Should I use a read replica for Bonnard?**

Recommended for production workloads. Point Bonnard at a read replica to isolate analytics queries from your application traffic. Combined with pre-aggregation caching, this keeps your primary database load unchanged.

**Can I use pre-aggregations with PostgreSQL?**

Yes. The [pre-aggregation](/glossary/pre-aggregation) cache handles this automatically. Define rollups in your cube YAML files and Bonnard builds and refreshes them on schedule. This offloads repeated analytical queries from your Postgres instance.

**Does Bonnard work with Supabase and Neon?**

Yes. Both Supabase and Neon expose standard Postgres connections. Copy your connection string, add it to `datasources.yml`, and run `bon deploy`. No additional configuration needed. Your Supabase or Neon database becomes queryable through the [semantic layer](/semantic-layer) and [agentic analytics](/agentic-analytics) surfaces.

## Related

- [DuckDB integration](/integrations/duckdb) -- for development and testing
- [What is Embedded Analytics?](/glossary/embedded-analytics) -- ship charts in your product
- [Bonnard vs Metabase](/vs-metabase) -- if you're currently using Metabase with Postgres