How to Manage Multiple Database Services on macOS with Homebrew
Modern applications often require multiple database systems running simultaneously. You might have PostgreSQL for your main app, Redis for caching, MySQL for a legacy project, and MongoDB for analytics—all running on your Mac.
Managing multiple databases can be tricky. Port conflicts, version mismatches, and resource consumption can make local development frustrating. In this guide, we'll cover best practices for managing multiple database services on macOS using Homebrew.
Common Database Services for macOS Developers
Here are the most popular databases installed via Homebrew:
Relational Databases:
- PostgreSQL - Most popular open-source SQL database
- MySQL/MariaDB - Widely used SQL database
- SQLite - Embedded file-based database (no service needed)
NoSQL Databases:
- Redis - In-memory key-value store and cache
- MongoDB - Document database
- Elasticsearch - Search and analytics engine
Message Queues (Database-adjacent):
- RabbitMQ - Message broker
- Apache Kafka - Distributed streaming platform
Most developers run 3-5 of these simultaneously during active development.
Installing Multiple Databases with Homebrew
Basic Installation
# Install PostgreSQL
brew install postgresql@17
# Install MySQL
brew install mysql
# Install Redis
brew install redis
# Install MongoDB
brew tap mongodb/brew
brew install mongodb-community
# Install Elasticsearch
brew install elasticsearch
Installing Specific Versions
You can run multiple versions of the same database side-by-side:
# Install different PostgreSQL versions
brew install postgresql@17 # Latest
brew install postgresql@15 # Older version for legacy project
# Install different MySQL versions
brew install mysql # Latest (currently 8.x)
brew install mysql@5.7 # Older version
Managing Service Startup
Starting Services Manually
# Start individual services
brew services start postgresql@17
brew services start mysql
brew services start redis
# Check running services
brew services list
Auto-Start vs Manual Start
Auto-start (services start at system boot):
brew services start postgresql@17 # Runs at login
Manual start (only when you need it):
brew services run postgresql@17 # Runs once, stops at logout
Best Practice: Only auto-start databases you use daily. Start others manually to save resources.
Avoiding Port Conflicts
By default, databases use these ports:
| Database | Default Port |
|---|---|
| PostgreSQL | 5432 |
| MySQL | 3306 |
| Redis | 6379 |
| MongoDB | 27017 |
| Elasticsearch | 9200 |
Running Multiple Versions on Different Ports
When running PostgreSQL 15 and 17 simultaneously, configure different ports:
1. Find config files:
# PostgreSQL config locations
/opt/homebrew/var/postgresql@17/postgresql.conf # Apple Silicon
/usr/local/var/postgresql@17/postgresql.conf # Intel
2. Edit postgresql.conf:
# PostgreSQL 17 stays on default port 5432
port = 5432
# PostgreSQL 15 uses alternate port
port = 5433
3. Connect to specific versions:
# Connect to PostgreSQL 17
psql -p 5432 -U youruser dbname
# Connect to PostgreSQL 15
psql -p 5433 -U youruser dbname
Resource Optimization Tips
Running multiple databases can consume significant CPU and RAM. Here's how to optimize:
1. Configure Memory Limits
PostgreSQL (postgresql.conf):
shared_buffers = 256MB # Reduce from default 128MB
effective_cache_size = 1GB # Adjust based on total RAM
work_mem = 16MB # Per-query memory
MySQL (my.cnf):
innodb_buffer_pool_size = 512M # Main memory pool
max_connections = 50 # Reduce if unused
Redis (redis.conf):
maxmemory 256mb # Set memory limit
maxmemory-policy allkeys-lru # Eviction policy
2. Stop Unused Services
Don't leave databases running when not actively developing:
# Stop services you're not using
brew services stop mongodb-community
brew services stop elasticsearch
# Restart when needed
brew services start mongodb-community
3. Use Service Groups
Create shell aliases for common service combinations:
# Add to ~/.zshrc or ~/.bashrc
# Start all database services
alias db-start='brew services start postgresql@17 && brew services start mysql && brew services start redis'
# Stop all database services
alias db-stop='brew services stop postgresql@17 && brew services stop mysql && brew services stop redis'
# Start only database servers (not message queues)
alias db-sql='brew services start postgresql@17 && brew services start mysql'
Using BrewMate for Multi-Database Management
Manually managing multiple databases via CLI becomes tedious. BrewMate simplifies this significantly:
Service Groups Feature
Create custom groups like:
- "Database Servers" - PostgreSQL, MySQL, Redis
- "Full Stack" - Databases + Nginx + message queues
- "Project Alpha" - Only services for specific project
Start/stop entire groups with one click.
Resource Monitoring
See which databases are consuming the most resources:
- Real-time CPU usage per service
- Memory consumption tracking
- Identify resource hogs instantly
Quick Log Access
When a database won't start, view logs immediately:
- One-click log viewer
- Search error messages
- No need to navigate
/opt/homebrew/var/log/
Common Multi-Database Scenarios
Scenario 1: Microservices Developer
Services needed:
- PostgreSQL (user service)
- MySQL (legacy auth service)
- Redis (session cache)
- MongoDB (logging service)
- RabbitMQ (message queue)
Strategy:
- Auto-start: PostgreSQL, Redis (used daily)
- Manual start: MySQL, MongoDB, RabbitMQ (project-specific)
- Use service groups to start project-specific stacks
Scenario 2: Full-Stack Developer
Services needed:
- PostgreSQL (primary DB)
- Redis (caching)
- Elasticsearch (search)
Strategy:
- Auto-start: PostgreSQL, Redis
- Manual start: Elasticsearch (only during search development)
- Monitor memory usage to prevent MacBook fan noise
Scenario 3: Consultant with Multiple Client Projects
Services needed:
- PostgreSQL 17 (Client A)
- PostgreSQL 15 (Client B - legacy)
- MySQL (Client C)
- MongoDB (Client D)
Strategy:
- Configure different ports for PostgreSQL versions
- Create service groups per client
- Stop all services between client switches
- Use database-specific connection strings in
.envfiles
Troubleshooting Multi-Database Issues
Problem: Service Won't Start
Solution:
# Check if port is already in use
lsof -i :5432 # PostgreSQL
lsof -i :3306 # MySQL
# View detailed error logs
tail -f /opt/homebrew/var/log/postgresql@17.log
# Restart with verbose output
brew services restart postgresql@17
Problem: Too Much Memory Usage
Solution:
- Check memory usage: Activity Monitor or BrewMate
- Stop unused services
- Reduce buffer sizes in config files
- Consider using Docker for resource isolation
Problem: Data Corruption After Crash
PostgreSQL recovery:
# Stop service
brew services stop postgresql@17
# Run recovery
pg_ctl -D /opt/homebrew/var/postgresql@17 start
# If corrupted, restore from backup
pg_restore -d dbname backup.dump
Best Practices Summary
✅ DO:
- Only auto-start databases you use daily
- Configure memory limits for each service
- Use different ports for multiple versions
- Create service groups for different projects
- Monitor resource usage regularly
- Keep databases updated (
brew upgrade)
❌ DON'T:
- Run all services simultaneously if not needed
- Ignore log errors
- Use default configurations for production-like loads
- Forget to backup important data (
pg_dump,mysqldump)
Simplify Multi-Database Management with BrewMate
Managing 5+ database services via CLI commands is tedious. BrewMate makes it effortless:
- See all services at a glance - Visual status indicators
- One-click start/stop - No typing commands
- Service groups - Start project-specific database stacks
- Resource monitoring - Identify memory hogs instantly
- Log viewer - Debug startup issues faster
Start Your 14-Day Free Trial →
Running into database management issues? Contact our support team or read our Homebrew CLI comparison guide.
Ready to try BrewMate?
Manage your Homebrew services with a beautiful native macOS app. Start your 14-day free trial today.
Download Free Trial