Skip to main content
The Convex backend is designed to work with SQLite, PostgreSQL, or MySQL. By default, the Docker image uses SQLite, which is great for getting started. For production workloads requiring guaranteed uptime, we recommend using a managed PostgreSQL or MySQL service.
It’s very important your backend is hosted in the same region and as close as possible to your database. Any additional latency between backend and database will negatively impact query performance.

Supported databases

  • SQLite: Default, built-in (no configuration needed)
  • PostgreSQL: Version 17 and compatible versions
  • MySQL: Version 8 and compatible versions

Migrating between databases

Use npx convex export to export your data before moving from one database provider to another:
After setting up your new database, import the data:

PostgreSQL setup

Neon provides managed PostgreSQL with automatic scaling and branching.
1

Create a database on Neon

Copy the connection string from the Neon dashboard.
2

Create the Convex database

3

Set the POSTGRES_URL environment variable

Extract the connection string without the database name and query parameters:
This should result in a URL ending in neon.tech:
4

Configure your deployment

Add to your .env file:
.env
Or set as a secret on your hosting platform:
5

Restart the backend

Check the logs for a line like:
6

Deploy your functions

Redeploy your Convex functions to the new database:

Using local PostgreSQL

For local development:
1

Create the database

2

Set environment variables

Create a .env file with your PostgreSQL connection:
.env
Only use DO_NOT_REQUIRE_SSL=1 for local development. Production deployments should use SSL.
3

Start the backend

Custom database names

The database name is derived from your instance name (with - replaced by _):
.env
Create the corresponding database:

MySQL setup

Using PlanetScale

PlanetScale provides managed MySQL with Vitess.
1

Create a database on PlanetScale

Create a database named convex_self_hosted in the PlanetScale dashboard.
2

Get the connection string

Copy the connection string from PlanetScale. Do not include the database name in MYSQL_URL.
3

Configure your deployment

Add to your .env file:
.env
4

Start the backend

Using local MySQL

For local development:
1

Create the database

2

Set environment variables

Create a .env file:
.env
Only use DO_NOT_REQUIRE_SSL=1 for local development. Production deployments should use SSL.
3

Start the backend

Database naming conventions

The Convex backend connects to a database with the same name as your instance:
  • Default instance name: convex-self-hosted
  • Default database name: convex_self_hosted (hyphens replaced with underscores)
To use a custom database name, set the INSTANCE_NAME environment variable:
.env
Then create the corresponding database:

Connection string format

PostgreSQL

Important: POSTGRES_URL should NOT include the database name or query parameters:

MySQL

Important: MYSQL_URL should NOT include the database name or query parameters:

Verification

After configuring your database, verify the connection:
1

Check the logs

Look for connection confirmation:
You should see:
or
2

Deploy functions

Deploy your Convex functions to ensure everything works:
3

Test the deployment

Run a test query:

Troubleshooting

Connection errors

If you see connection errors in the logs:
  1. Verify the connection string: Ensure it doesn’t include the database name or query parameters
  2. Check region/latency: Ensure your backend is in the same region as your database
  3. Verify SSL settings: Use DO_NOT_REQUIRE_SSL=1 only for local development
  4. Check firewall rules: Ensure your hosting platform can access your database

Database not found

If you see “database not found” errors:
  1. Verify database exists: Check that you created the database with the correct name
  2. Check instance name: Ensure the database name matches your instance name (with hyphens replaced by underscores)
  3. Verify permissions: Ensure your database user has access to the database

Performance issues

  1. Check latency: Use ping or similar tools to measure latency between backend and database
  2. Same region: Ensure backend and database are in the same region
  3. Connection pooling: Managed services typically handle this automatically

Example configurations

Production with Neon PostgreSQL

.env

Production with PlanetScale MySQL

.env

Local development with PostgreSQL

.env

Next steps

Storage

Configure S3-compatible storage for files and exports

Configuration

Explore all runtime configuration options