Skip to main content
Evolution API requires a database to store instance data, messages, contacts, and configuration. This guide covers database setup, connection configuration, and schema management.

Supported Databases

Evolution API supports three database configurations:
  • PostgreSQL - Recommended for production deployments
  • MySQL - Alternative for MySQL-based infrastructures
  • PostgreSQL with PgBouncer - For high-concurrency deployments

Database Provider

Set the database provider in your .env file:
enum
required
Database provider to use. Options:
  • postgresql - Standard PostgreSQL connection
  • mysql - MySQL/MariaDB connection
  • psql_bouncer - PostgreSQL with PgBouncer connection pooling

PostgreSQL Setup

Installation

Use the official PostgreSQL Docker image:

Connection URI Format

Configure the PostgreSQL connection in your .env file:
Example:
URI Components:
  • evolution - Database username
  • your_password - Database password
  • localhost - Database host (use container name in Docker)
  • 5432 - PostgreSQL port
  • evolution_db - Database name
  • evolution_api - Prisma schema name

Performance Tuning

For production deployments, optimize PostgreSQL configuration:

MySQL Setup

Installation

Use the official MySQL Docker image:

Connection URI Format

Configure the MySQL connection in your .env file:
Example:

PgBouncer Configuration

PgBouncer provides connection pooling for high-concurrency deployments.

Setup with Docker Compose

docker-compose.yaml

Connection Configuration

Use both connection URIs when using PgBouncer:

Database Migrations

Evolution API uses Prisma for database schema management.

Environment Setup

Always set DATABASE_PROVIDER before running migration commands.

Generate Prisma Client

Generate the Prisma client for your database provider:
This reads the schema from:
  • prisma/postgresql-schema.prisma for PostgreSQL
  • prisma/mysql-schema.prisma for MySQL

Run Migrations

For development environments:
This creates migration files and applies them to the database.

Docker Automatic Migrations

When using the official Docker image, migrations run automatically on startup:
The deploy_database.sh script:
  1. Detects the database provider from DATABASE_PROVIDER
  2. Generates the correct Prisma client
  3. Runs pending migrations
  4. Starts the application

Database Schema

Evolution API’s database schema includes tables for:

Core Tables

Instance - WhatsApp instance information
Message - WhatsApp messages
Contact - WhatsApp contacts
Chat - WhatsApp conversations

Integration Tables

  • Webhook - Webhook configurations
  • Chatwoot - Chatwoot CRM integration
  • Typebot - Typebot chatbot integration
  • OpenaiBot - OpenAI chatbot integration
  • Dify - Dify AI integration
  • Rabbitmq - RabbitMQ event configuration
  • Sqs - AWS SQS event configuration
  • Websocket - WebSocket event configuration

Prisma Studio

Browse and edit your database with Prisma Studio:
This opens a web interface at http://localhost:5555 for database management.

Data Storage Options

Control what data is saved to the database:
.env
Disabling data storage options reduces database size but limits API functionality like message history and contact retrieval.

Client Name Separation

When running multiple Evolution API installations on the same database:
This separates data between installations sharing the same database instance.

Backup and Restore

PostgreSQL Backup

MySQL Backup

Automated Backups

Set up automated daily backups with cron:

Troubleshooting

If Evolution API cannot connect to the database:
  1. Verify the database is running:
  2. Check connection URI format is correct
  3. Verify username and password
  4. Ensure the database exists:
  5. Check firewall rules allow connections on port 5432/3306
If migrations fail:
  1. Ensure DATABASE_PROVIDER is set correctly:
  2. Verify database connection before running migrations:
  3. Check migration files exist:
  4. Reset migrations (development only):
For authentication errors:
  1. Verify username and password in connection URI
  2. Check user permissions:
  3. Ensure user has necessary privileges:
To optimize query performance:
  1. Enable query logging:
  2. Analyze slow queries:
  3. Create indexes for frequently queried columns
  4. Increase shared_buffers and effective_cache_size
  5. Consider using PgBouncer for connection pooling

Security Best Practices

  1. Use strong passwords - Generate random passwords for database users
  2. Limit network access - Bind database to localhost or private network only
  3. Enable SSL/TLS - Use encrypted connections in production
  4. Regular backups - Implement automated backup strategies
  5. Update regularly - Keep database software up to date
  6. Monitor access - Enable and review database audit logs
  7. Principle of least privilege - Grant only necessary permissions

Next Steps

Environment Variables

Configure all Evolution API settings

Docker Deployment

Deploy Evolution API with Docker Compose