Overview
Databuddy uses two primary databases:- PostgreSQL - User accounts, organizations, websites, API keys
- ClickHouse - Analytics events, metrics, and time-series data
- Redis - Caching and session management
PostgreSQL Setup
PostgreSQL stores all relational data for Databuddy.Installation
- Docker Compose
- Ubuntu/Debian
- macOS
The included Start PostgreSQL:
docker-compose.yaml provides PostgreSQL 17:Database Connection
Configure the PostgreSQL connection in.env:
postgres://username:password@host:port/database
Running Migrations
Databuddy uses Drizzle ORM for database migrations.Generate migration files
After modifying the schema:This creates SQL migration files in
packages/db/migrations/.Database Schema Overview
PostgreSQL stores the following tables: User Management:user- User accountsaccount- OAuth provider accountssession- User sessionsverification- Email verification tokens
organization- Organization/team recordsorganization_member- Team membershiporganization_invite- Pending invites
website- Tracked websites/appsapi_key- API authentication keysfunnel- Conversion funnelsgoal- Goal tracking configuration
subscription- Payment subscriptionsusage_record- Usage tracking
packages/db/src/drizzle/schema.ts.
Database Backup
Backup your PostgreSQL database regularly:ClickHouse Setup
ClickHouse stores all analytics events and time-series metrics.Installation
- Docker Compose
- Ubuntu/Debian
- macOS
The included Start ClickHouse:
docker-compose.yaml provides ClickHouse 25.5.1:ClickHouse Connection
Configure the ClickHouse connection in.env:
http://username:password@host:port/database
Initialize ClickHouse Schema
Databuddy provides a script to initialize all ClickHouse tables:- Three databases:
analytics,uptime,observability - All required tables and materialized views
ClickHouse Schema Overview
ClickHouse stores the following tables: Analytics Database:events - Core analytics events
events - Core analytics events
Primary table for pageviews, custom events, and user interactions.Key fields:
client_id- Website/app identifieranonymous_id- User identifiersession_id- Session trackingevent_name- Event type (screen_view, click, etc.)url,path- Page informationcountry,city- Geo databrowser_name,os_name,device_type- Device info
error_spans - Error tracking
error_spans - Error tracking
JavaScript errors and exceptions.Key fields:
message- Error messagefilename,lineno,colno- Error locationstack- Stack traceerror_type- Error classification
web_vitals_spans - Performance metrics
web_vitals_spans - Performance metrics
Core Web Vitals and performance data.Metrics tracked:
- LCP (Largest Contentful Paint)
- FCP (First Contentful Paint)
- CLS (Cumulative Layout Shift)
- INP (Interaction to Next Paint)
- TTFB (Time to First Byte)
- FPS (Frames Per Second)
custom_events - API-generated events
custom_events - API-generated events
Server-side events sent via API.Key fields:
owner_id- Organization IDevent_name- Custom event namenamespace- Optional groupingproperties- JSON event data
revenue - Payment transactions
revenue - Payment transactions
Revenue tracking from Stripe/Paddle.Key fields:
transaction_id- Unique transactionprovider- Payment processoramount- Transaction amountcurrency- Currency codeanonymous_id- Attribution to user
ai_traffic_spans - AI bot detection
ai_traffic_spans - AI bot detection
AI crawlers and assistant traffic.Key fields:
bot_type- ai_crawler or ai_assistantbot_name- Detected bot (GPTBot, Claude-Web, etc.)path- Page accessed
blocked_traffic - Bot blocking
blocked_traffic - Bot blocking
Blocked requests from bots and bad actors.Key fields:
block_reason- Why blockedblock_category- Blocking rulebot_name- Detected bot if applicableip,user_agent- Request details
uptime_monitor- Website uptime monitoring data
ai_call_spans- LLM API call tracking (tokens, cost, latency)
Materialized Views
Databuddy uses materialized views for pre-aggregated data:error_hourly_mv→error_hourly- Hourly error aggregatesweb_vitals_hourly_mv→web_vitals_hourly- Hourly performance statsdaily_pageviews_mv→daily_pageviews- Daily pageview counts
ClickHouse Optimization
For production deployments:ClickHouse Backup
Backup ClickHouse data:Redis Setup
Redis provides caching and session storage.Installation
- Docker Compose
- Ubuntu/Debian
- macOS
The included Start Redis:
docker-compose.yaml provides Redis 7:Redis Connection
Redis Configuration
Databuddy uses Redis for:- Session storage
- Query result caching (TTL: 5 minutes)
- Rate limiting
- Background job queues
Database Monitoring
PostgreSQL Monitoring
ClickHouse Monitoring
Troubleshooting
PostgreSQL connection failed
PostgreSQL connection failed
Check connection string and PostgreSQL service:
ClickHouse tables not created
ClickHouse tables not created
Verify ClickHouse is running and accessible:
Migrations failing
Migrations failing
Check for schema conflicts:
ClickHouse out of memory
ClickHouse out of memory
Increase memory limits or adjust query settings:In docker-compose.yaml:
Next Steps
Environment Variables
Configure authentication, integrations, and features
Configuration
Advanced configuration and tuning