Requirements
- PostgreSQL: Version 13 or higher
- Storage: Minimum 20GB, recommended 100GB+ for production
- Memory: Minimum 2GB RAM allocated to PostgreSQL
- Connection Limit: Adjust based on your deployment scale
Database Setup
Local PostgreSQL Installation
Ubuntu/Debian
macOS
Windows
Download from postgresql.org and follow the installer.Create Database
Connection String Format
PostgreSQL connection strings follow this format:Environment Configuration
Add to your.env file:
Migrations
Cal.com uses Prisma for database schema management and migrations.Initial Setup
For a new database, run migrations to create all tables:Migration Commands
Migration Best Practices
The Docker
start.sh script automatically runs migrations on container startup:Schema Location
The Prisma schema is located at:Migration Directory
Migration files are stored in:Connection Pooling
Why Use Connection Pooling?
Connection poolers like PgBouncer help:- Reduce database connection overhead
- Handle high-concurrency workloads
- Manage connection limits efficiently
- Improve application performance
PgBouncer Setup
Using Docker
Configuration
Update your.env to use PgBouncer:
DATABASE_DIRECT_URL must point to the actual database (not pooler) for migrations to work correctly.Managed Pooling Services
Many providers offer built-in connection pooling:Supabase
Railway
Railway automatically provides both pooled and direct connections.Neon
Managed Database Providers
Railway
- Create a new PostgreSQL database in Railway
- Copy the connection string from Railway dashboard
- Add to
.env:
Render
- Create a new PostgreSQL database in Render
- Get external connection string
- Configure:
Supabase
- Create a new Supabase project
- Get connection strings from Settings > Database
- Use pooled connection for app, direct for migrations:
Neon
- Create a Neon project
- Get pooled and direct connection strings
- Configure:
Amazon RDS
- Create RDS PostgreSQL instance
- Configure security groups for access
- Get endpoint from RDS console:
SSL Configuration
Requiring SSL
Self-Signed Certificates
For platforms like Heroku with self-signed certs:SSL Modes
disable: No SSLprefer: Try SSL, fallback to non-SSLrequire: Require SSL, but don’t verify certificatesverify-ca: Require SSL and verify certificateverify-full: Require SSL, verify certificate and hostname
Database Optimization
Indexes
Cal.com’s schema includes optimized indexes. Monitor slow queries:Connection Limits
Adjust PostgreSQL connection limits inpostgresql.conf:
Vacuum and Analyze
Enable auto-vacuum for maintenance:Backup Strategies
pg_dump Backup
Continuous Archiving (WAL)
For point-in-time recovery, enable WAL archiving:Managed Backups
Most managed providers offer automatic backups:- Supabase: Daily backups with point-in-time recovery
- Railway: Automatic daily backups
- Render: Daily backups included
- RDS: Automated backups with configurable retention
Database Management Tools
Prisma Studio
Visual database browser included with Cal.com:Prisma Studio is available in the Docker Compose setup at port 5555. Remove this service in production.
pgAdmin
Full-featured PostgreSQL management:psql CLI
Connect directly to your database:Docker Compose Database
The defaultdocker-compose.yml includes PostgreSQL:
Separate Databases
Insights Database
For analytics workload isolation:SAML Database (Enterprise)
For SAML SSO data:Troubleshooting
Connection Refused
- Verify PostgreSQL is running:
sudo systemctl status postgresql - Check port:
sudo netstat -plnt | grep 5432 - Review
pg_hba.conffor connection permissions
Too Many Connections
- Implement connection pooling (PgBouncer)
- Increase
max_connectionsin PostgreSQL - Check for connection leaks in application
Migration Failures
- Use
DATABASE_DIRECT_URL(not pooled connection) - Check database permissions
- Review migration logs:
yarn workspace @calcom/prisma db-migrate status - Manually resolve conflicts in failed migrations
Permission Denied
Authentication Failed
- Verify credentials in
DATABASE_URL - URL-encode special characters in password
- Check
pg_hba.confauthentication method (md5/scram-sha-256)
Performance Monitoring
Query Statistics
Enablepg_stat_statements extension:
Connection Monitoring
Production Checklist
- Use PostgreSQL 13 or higher
- Configure strong database credentials
- Enable SSL connections (
sslmode=require) - Set up connection pooling (PgBouncer or managed)
- Configure
DATABASE_URLandDATABASE_DIRECT_URL - Run migrations with
db-deploy - Enable automated backups
- Configure backup retention policy
- Set up monitoring and alerts
- Optimize PostgreSQL configuration for your workload
- Plan for database scaling (read replicas, etc.)
- Document recovery procedures
- Test backup restoration process
Next Steps
- Review Configuration for database-related environment variables
- See Docker Setup for containerized database deployment
- Check Deployment for platform-specific database configurations