Overview
WhatsApp Team Inbox uses PostgreSQL to store conversations, messages, team members, and configuration. This guide covers database setup for both local development and production deployment.PostgreSQL 14 or higher is recommended for optimal performance and features.
Database Options
- Supabase (Recommended)
- Neon
- Railway
- Self-Hosted
Managed PostgreSQL with built-in auth, real-time subscriptions, and automatic backups.Free Tier:
- 500 MB database
- Unlimited API requests
- 50,000 monthly active users
- Automatic backups (7 days)
- Free: Perfect for getting started
- Pro: $25/mo (8 GB database, daily backups)
- Team: $599/mo (unlimited projects)
- Quick setup and deployment
- Small to medium teams
- Teams wanting managed infrastructure
Supabase Setup (Recommended)
1
Create Supabase Project
- Go to supabase.com
- Click Start your project
- Sign in with GitHub (recommended)
- Click New project
- Fill in project details:
- Name: whatsapp-team-inbox
- Database Password: Generate a strong password (save it!)
- Region: Choose closest to your users
- Pricing Plan: Free (to start)
- Click Create new project
- Wait 2-3 minutes for provisioning
2
Get Database Credentials
- Go to Project Settings > Database
- Find Connection string section
- Copy the URI connection string:
- Replace
[YOUR-PASSWORD]with your actual password
.env file:3
Enable Connection Pooling
For production, enable connection pooling:
- In Supabase dashboard, go to Database > Connection Pooling
- Enable Session Mode or Transaction Mode
- Copy the pooler connection string:
.env:Connection pooling prevents “too many connections” errors under load.
4
Configure Database Settings
Optimize for Team Inbox workload:
- Go to Database > Settings
- Update these settings:
- Statement timeout: 30000ms (30 seconds)
- Max connections: 100 (free tier)
- Shared buffers: Default (managed by Supabase)
- Increasing max connections to 200-500
- Enabling point-in-time recovery
5
Run Database Migrations
Initialize the database schema:This creates all necessary tables:
users- Team membersconversations- WhatsApp conversationsmessages- Individual messagescontacts- Customer contact informationassignments- Conversation assignmentsnotifications- User notificationswebhooks- Webhook configurations
6
Seed Initial Data (Optional)
Add sample data for testing:This creates:
- Demo admin user
- Sample conversations
- Test contacts
Self-Hosted PostgreSQL Setup
1
Install PostgreSQL
- Ubuntu/Debian
- macOS
- Docker
- Windows
2
Create Database and User
.env:3
Configure PostgreSQL
Edit PostgreSQL configuration for production:Recommended settings:Restart PostgreSQL:
4
Set Up Backups
Create automated backup script:Add this content:Make executable and schedule:
Database Schema
The Team Inbox uses these main tables:Users Table
Conversations Table
Messages Table
Contacts Table
Database Migrations
The application uses Prisma for database migrations:Create a New Migration
Apply Migrations in Production
Reset Database (Development Only)
View Migration Status
Performance Optimization
1
Add Database Indexes
Critical indexes for Team Inbox:
2
Enable Query Logging
Monitor slow queries:
3
Configure Connection Pool
Optimize database connections:
4
Implement Caching
Use Redis for frequently accessed data:
Monitoring and Maintenance
Monitor Connection Count
Check Database Size
Find Slow Queries
Vacuum Database
Backup and Recovery
Automated Backups (Supabase)
Supabase provides automatic daily backups on Pro plan:- Go to Database > Backups
- View available backups
- Restore from backup:
- Click Restore on desired backup
- Confirm restoration
- Wait for completion (5-10 minutes)
Manual Backup
Backup to Cloud Storage
Troubleshooting
Connection refused errors
Connection refused errors
Causes:
- PostgreSQL not running
- Wrong host/port
- Firewall blocking connections
Too many connections
Too many connections
Error:
FATAL: sorry, too many clients alreadySolutions:- Enable connection pooling
- Increase
max_connectionsin postgresql.conf - Fix connection leaks in application code
- Use PgBouncer for connection pooling
Slow query performance
Slow query performance
Solutions:
- Add missing indexes
- Analyze query execution plan
- Optimize queries
- Increase database resources
Disk space filling up
Disk space filling up
Solutions:
- Clean up old data
- Archive old conversations
- Run VACUUM
- Increase disk size
Security Best Practices
Use SSL Connections
Enable SSL for database connections in production
Restrict Access
Use firewall rules to limit database access
Regular Backups
Automate daily backups with retention policy
Strong Passwords
Use long, complex passwords for database users