Skip to main content
SaaS Starter Vue uses PostgreSQL as the primary database with a multi-tenant architecture powered by Stancl/Tenancy. Each tenant gets their own isolated database.

Database Architecture

The application uses a multi-database tenancy approach:
  • Central Database: Stores system-wide data (tenants, plans, subscriptions, domains)
  • Tenant Databases: Each tenant gets their own PostgreSQL database for isolated data storage
This architecture provides complete data isolation between tenants and makes backup/restore operations per-tenant easier.

PostgreSQL Setup

Local Development

Install PostgreSQL on your system:
Create the central database:

Environment Configuration

Configure your database connection in .env:
DB_CONNECTION
string
default:"pgsql"
required
The database driver to use. For this application, use pgsql for PostgreSQL.
DB_HOST
string
default:"127.0.0.1"
The database server hostname or IP address.
DB_PORT
integer
default:"5432"
The PostgreSQL server port.
DB_DATABASE
string
required
The name of your central database.
DB_USERNAME
string
required
Database username with permissions to create databases (required for tenant database creation).
DB_PASSWORD
string
required
Database password for authentication.
DB_CHARSET
string
default:"utf8"
Character set for the database connection.
DB_SSLMODE
string
default:"prefer"
SSL mode for PostgreSQL connections. Options: disable, allow, prefer, require, verify-ca, verify-full

Example Configuration

Running Migrations

Central Database Migrations

Run migrations for the central database (tenants, plans, subscriptions):
This creates the following central tables:
  • tenants - Tenant information and metadata
  • domains - Custom domains for tenants
  • plans - Subscription plans
  • subscriptions - Tenant subscription data
  • features - Available features for plans
  • activity_logs - System activity tracking
  • settings - Global application settings

Tenant Database Migrations

Create and migrate a tenant database:
Tenant migrations are located in database/migrations/tenant/ and run automatically when new tenants are created.

Database Schema Overview

Central Database Tables

Tenants Table

Stores all tenant information:

Domains Table

Manages custom domains for tenants:

Plans Table

Defines available subscription plans:

Subscriptions Table

Tracks tenant subscriptions:

Features Table

Defines available features:

Tenant Database Tables

Each tenant database contains:
  • users - Tenant-specific users
  • password_reset_tokens - Password reset tokens
  • sessions - User sessions
  • personal_access_tokens - API tokens
  • jobs - Background job queue
  • cache - Cache storage
  • settings - Tenant-specific settings

Tenancy Configuration

The multi-tenant behavior is configured in config/tenancy.php:
Tenant databases are named: tenant{tenant_id} For example, a tenant with ID abc123 gets database: tenantabc123

Database Management Commands

Tenant Operations

Database Maintenance

Production Considerations

Database User Permissions: The database user must have CREATEDB privilege to create tenant databases automatically.

Grant Database Creation Rights

Connection Pooling

For production, use connection pooling with PgBouncer:

Performance Tuning

Optimize PostgreSQL for Laravel:

Backup Strategy

  1. Central Database: Daily automated backups
  2. Tenant Databases: Per-tenant backup schedules
  3. Point-in-Time Recovery: Enable WAL archiving

Troubleshooting

Connection Issues

Permission Errors

Tenant Database Issues

Next Steps