Metabase + PostgreSQL: Build Interactive Dashboards Without Writing SQL

Metabase + PostgreSQL: Build Interactive Dashboards Without Writing SQL

Your database is full of answers. Sales trends, customer behavior, product performance. But getting those answers usually means writing SQL queries, waiting for engineering, or paying for expensive BI tools that require a data analyst to operate.

Metabase changes that equation. It connects directly to your PostgreSQL database and lets anyone on your team build dashboards through a visual interface. No SQL required for most questions. And when you do need custom queries, they're right there too.

Why Metabase Works for Technical Teams

Most BI tools fall into two camps: enterprise behemoths that cost six figures annually, or spreadsheet plugins that break when your data grows. Metabase sits in the sweet spot.

It's open-source, runs anywhere Docker runs, and handles real workloads. Connect it to your production replica, set up some basic permissions, and suddenly your product manager can answer their own questions about user signups without filing a ticket.

The technical win here is reducing interrupt-driven analytics work. Every "quick question" from marketing that pulls an engineer away for 30 minutes adds up. Metabase makes those questions self-service.

Connecting to PostgreSQL

The setup is straightforward. After deploying Metabase, add your database connection:

Host: your-postgres-host.example.com
Port: 5432
Database name: production_replica
Username: metabase_readonly
Password: [your secure password]

Create a read-only PostgreSQL user for Metabase. Never connect with your application's credentials:

CREATE USER metabase_readonly WITH PASSWORD 'secure_password';
GRANT CONNECT ON DATABASE production_replica TO metabase_readonly;
GRANT USAGE ON SCHEMA public TO metabase_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO metabase_readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
  GRANT SELECT ON TABLES TO metabase_readonly;

This setup ensures Metabase can read data but never modify it. The ALTER DEFAULT PRIVILEGES line covers future tables automatically.

Building Dashboards Without SQL

Metabase scans your database schema and presents tables as "models" in its interface. Your team can ask questions like:

  • "Show me orders from the last 30 days"
  • "Count users grouped by signup month"
  • "Average order value by product category"

All through point-and-click. Select a table, choose columns, add filters, pick a visualization. The query builder handles JOINs, aggregations, and date math behind the scenes.

For a sales dashboard, you might create:

  1. Daily Revenue Chart: Orders table, sum of total_amount, grouped by created_at (by day)
  2. Top Products: Order items joined to products, count by product_name, sorted descending
  3. Customer Acquisition: Users table, count grouped by created_at (by week)

Drag these onto a dashboard, set auto-refresh to hourly, and share the link. Done.

When You Need Custom SQL

The visual builder covers 80% of questions. For the rest, Metabase has native SQL queries with some useful additions:

SELECT
  date_trunc('week', created_at) as week,
  COUNT(*) as signups,
  COUNT(*) FILTER (WHERE subscription_plan = 'paid') as paid_signups
FROM users
WHERE created_at >= {{start_date}}
  AND created_at <= {{end_date}}
GROUP BY 1
ORDER BY 1

Those {{start_date}} variables become filter widgets in the UI. Non-technical users can adjust the date range without touching SQL.

You can also create "Questions" from SQL and let others build on top of them. Write the complex query once, expose it as a simple data source.

Embedding Dashboards in Your App

Metabase supports iframe embedding for internal tools. Generate a signed embed URL:

const jwt = require('jsonwebtoken');

const payload = {
  resource: { dashboard: 42 },
  params: { customer_id: currentUser.customerId },
  exp: Math.round(Date.now() / 1000) + (60 * 10) // 10 minutes
};

const embedUrl = `https://metabase.yourcompany.com/embed/dashboard/${
  jwt.sign(payload, METABASE_SECRET_KEY)
}#bordered=false&titled=false`;

This creates customer-specific dashboards filtered to their data. Useful for client portals, admin panels, or anywhere you need analytics without building custom charts.

Performance Considerations

A few things to keep Metabase running smoothly:

Use a replica: Never point Metabase at your primary database. Complex dashboard queries can impact application performance.

Cache aggressively: Metabase caches query results. For dashboards that don't need real-time data, set longer cache durations.

Index strategically: If a dashboard query is slow, check the generated SQL in Metabase and add appropriate indexes. The most common issue is missing indexes on columns used in WHERE clauses and JOINs.

Set query timeouts: Prevent runaway queries from consuming resources:

ALTER USER metabase_readonly SET statement_timeout = '30s';

Deploy on Elestio

Running Metabase yourself means managing Docker, SSL certificates, backups, and updates. Or you can deploy it in minutes on Elestio.

Elestio handles the infrastructure. You get a running Metabase instance with automated backups, SSL, and updates. Connect your PostgreSQL database and start building dashboards the same day.

For teams ready to turn their data into answers without the BI tool overhead, deploy Metabase on Elestio and see what your database has been trying to tell you.

Thanks for reading!