Database Setup
Umami requires PostgreSQL 12.14 or higher for storing analytics data. This guide covers database setup, optimization, and maintenance.Supported Databases
PostgreSQL
Recommended. Version 12.14+ required. Full feature support and best performance.
MySQL
Deprecated. Limited support in v2+. Not recommended for new installations.
Umami v2+ focuses on PostgreSQL. All new features and optimizations target PostgreSQL.
PostgreSQL Installation
Linux (Ubuntu/Debian)
macOS
- Homebrew
- Postgres.app
Windows
- Download installer from postgresql.org
- Run the installer
- Choose installation directory
- Set superuser password
- Select port (default: 5432)
- Complete installation
Docker
Run PostgreSQL in a container:Database Creation
Create Umami Database
Connection URL Format
Umami uses a PostgreSQL connection string:username: Database user (e.g.,umami)password: User passwordhostname: Server address (e.g.,localhost,db, or IP)port: PostgreSQL port (default:5432)database: Database name (e.g.,umami)
Schema Initialization
Umami automatically creates database tables on first build.Automatic Migration (Recommended)
When you run the build command, Umami:- Connects to the database
- Runs Prisma migrations
- Creates all required tables
- Sets up indexes
- Creates default admin user
The build process creates tables from the Prisma schema located at
prisma/schema.prisma.Manual Migration
If automatic migration fails:Verify Tables
Check that tables were created:Database Schema
Umami’s database schema includes:Core Tables
Core Tables
user: User accounts and authentication
user_id(UUID, primary key)username(unique)password(hashed with bcrypt)role(admin, user, view-only)created_at,updated_at
website_id(UUID, primary key)name,domainshare_id(for public dashboards)user_id,team_id- Timestamps
session_id(UUID, primary key)website_id- Browser, OS, device info
- Location data (country, region, city)
- Language, screen resolution
event_id(UUID, primary key)website_id,session_idurl,referrerevent_type,event_name- Timestamp
Additional Tables
Additional Tables
- event_data: Custom event properties
- session_data: Custom session data
- team: Team/organization management
- team_user: Team membership
- report: Custom reports
- revenue: Revenue tracking (optional)
Performance Optimization
Indexes
Umami automatically creates indexes for common queries:The Prisma schema defines all indexes. They’re created automatically during migration.
Vacuum and Analyze
Regularly maintain your database:Connection Pooling
For high-traffic sites, use connection pooling:- PgBouncer
- Prisma Connection Pool
- Cloud Providers
Install PgBouncer:Configure Update DATABASE_URL:
/etc/pgbouncer/pgbouncer.ini:Query Performance
Optimize slow queries:Backup and Restore
Backup Database
Restore Database
Automated Backups
Schedule regular backups with cron:cron
Data Retention
Clean Old Data
Remove old analytics data:Automated Cleanup
Create a cleanup script:cleanup.sql
Monitoring
Database Size
Active Connections
Performance Stats
Troubleshooting
Connection refused
Connection refused
Check PostgreSQL is running:Verify port is open:Check Add:
pg_hba.conf allows connections:Too many connections
Too many connections
Increase max connections in Or use connection pooling (PgBouncer).Restart PostgreSQL:
postgresql.conf:Slow queries
Slow queries
- Add missing indexes
- Run VACUUM ANALYZE
- Check pg_stat_statements for slow queries
- Optimize queries in application
- Consider upgrading hardware
- Use ClickHouse for very high volume
Disk space full
Disk space full
- Delete old analytics data
- Run VACUUM FULL to reclaim space
- Archive old data to backup
- Increase disk size
- Set up data retention policy
Next Steps
Environment Variables
Configure DATABASE_URL and other settings
Running in Production
Production deployment guide
Docker Installation
Deploy with Docker and PostgreSQL
Source Installation
Build from source with PostgreSQL