Skip to main content
Every Supabase project comes with a full PostgreSQL database, one of the world’s most stable and advanced relational databases. Supabase extends Postgres with real-time functionality, automatic APIs, and a suite of powerful extensions.

Architecture

Supabase Database is built on PostgreSQL with several key components:
  • PostgreSQL Core: Your database runs on a dedicated Postgres instance with full postgres level access
  • PostgREST: Automatically generates a RESTful API from your database schema
  • pg_graphql: Provides a GraphQL API for your data
  • Realtime Server: Broadcasts database changes via WebSockets
  • postgres-meta: A RESTful API for database management operations
All database operations go through the Kong API gateway, which handles authentication, rate limiting, and routing to the appropriate service.

Core Concepts

Tables and Schemas

PostgreSQL organizes data into tables within schemas. Supabase creates several schemas by default:
  • public: Your application tables (exposed via auto-generated APIs)
  • auth: User authentication data (managed by Supabase Auth)
  • storage: File metadata (managed by Supabase Storage)
  • extensions: PostgreSQL extensions
  • realtime: Real-time configuration
You can create tables using SQL or the Supabase Dashboard:

Row Level Security (RLS)

RLS is PostgreSQL’s built-in authorization system that allows you to control access to individual rows in your tables. Supabase enables RLS by default on new tables.
Without RLS policies, tables are not accessible via the auto-generated APIs. You must create policies to allow access.

Relationships

PostgreSQL supports foreign keys to define relationships between tables:
The Supabase Dashboard provides a visual interface to explore relationships and navigate between related data.

Indexes

Indexes improve query performance by allowing the database to find data without scanning every row:

Auto-generated APIs

Supabase automatically generates RESTful and GraphQL APIs from your database schema:

REST API (PostgREST)

GraphQL API

Database Functions

You can create custom functions in PostgreSQL to encapsulate business logic:
Call functions from your client:

Triggers

Triggers automatically execute functions in response to database events:

Extensions

Supabase provides access to over 50 PostgreSQL extensions. Enable them with a single click in the Dashboard:
  • pgvector: Store and query vector embeddings for AI applications
  • PostGIS: Geographic information system capabilities
  • pg_cron: Schedule periodic jobs
  • uuid-ossp: Generate UUIDs
  • pg_stat_statements: Track query performance

Database Management

Migrations

Use migrations to version control your database schema:
Apply migrations using the Supabase CLI:

Backups

Supabase manages automated backups for your database:
  • Free tier: Daily backups retained for 7 days
  • Pro tier: Daily backups retained for 14 days
  • Team tier: Daily backups retained for 28 days
  • Enterprise: Custom retention periods and Point-in-Time Recovery (PITR)
Database backups do not include Storage objects - only their metadata. Back up Storage buckets separately.

Performance Optimization

Connection Pooling

Supabase uses PgBouncer for connection pooling. You can access your database through two connection modes:
  • Session mode (Port 5432): Full PostgreSQL features, limited connections
  • Transaction mode (Port 6543): Higher concurrency, some feature limitations

Query Performance

Use the SQL Editor to analyze query performance:

Vacuum and Analyze

PostgreSQL automatically performs vacuum operations, but you can manually optimize:

Best Practices

Use RLS

Always enable Row Level Security and create appropriate policies for your tables.

Index Strategically

Create indexes on columns used in WHERE clauses and JOIN conditions.

Normalize Data

Design tables following database normalization principles to reduce redundancy.

Use Transactions

Wrap related operations in transactions to ensure data consistency.

Next Steps

Database Functions

Learn how to create custom database functions

Triggers

Automate database operations with triggers

Extensions

Extend PostgreSQL with powerful extensions

Migrations

Version control your database schema