PlanetScale
PlanetScale provides managed Postgres hosting with high-availability clusters.
Electric and PlanetScale
You can use Electric with PlanetScale for Postgres.
Need context?
See the Deployment guide for more details.
Setup Overview
PlanetScale has several unique characteristics that require special attention:
- Logical replication - Not enabled by default, must configure cluster parameters
- Connection limits - Default of 25 is too low for Electric's pool of 20
- Failover requirements - Replication slots must support failover
For general PostgreSQL user and permission setup, see the PostgreSQL Permissions guide.
Deploy Postgres
Sign up to PlanetScale and create a Postgres database.
Enable Logical Replication
Logical replication may not be enabled on your cluster. Verify and configure as needed. See the PlanetScale Logical Replication guide for detailed background.
Verify current configuration:
SHOW wal_level; -- Should return 'logical'If not enabled, configure in PlanetScale Console:
Go to your database → Settings → Cluster configuration → Parameters
Set these parameters:
wal_level=logicalmax_replication_slots=10(or higher)max_wal_senders=10(or higher)max_slot_wal_keep_size=4096(4GB minimum)sync_replication_slots=on(for failover support)hot_standby_feedback=on(for failover support)
Apply changes (may require cluster restart)
Failover Requirement
PlanetScale requires replication slots to support failover. Electric creates failover-enabled slots automatically, but your cluster must have sync_replication_slots = on configured.
Increase Connection Limits
Small PlanetScale clusters may start with a low max_connections limit. Electric uses 20 connections for its connection pool by default (configurable via ELECTRIC_DB_POOL_SIZE).
Connection Limit Issue
With a low connection limit, you may have limited headroom remaining for:
- Your application
- Database migrations
- Admin tools
- Connection poolers (Cloudflare, etc.)
Recommendation: Plan connection capacity for your expected concurrent database work. A good rule of thumb is ≥ 3× Electric's pool size to ensure adequate headroom (e.g., if Electric uses 20 connections, set max_connections to at least 60).
To increase connection limits in PlanetScale:
- Go to your database → Settings → Cluster configuration → Parameters
- Find
max_connectionsparameter - Increase based on your expected concurrent work (Electric pool size + application + admin tools + buffer)
Alternatively, reduce Electric's pool size if you have limited connections:
ELECTRIC_DB_POOL_SIZE=10Create Replication User
Follow the PostgreSQL Permissions guide to set up the Electric user with proper permissions.
PlanetScale-Specific Note
PlanetScale's default postgres role includes the REPLICATION attribute. You can use it directly, or create a dedicated replication role for least-privilege access per your organization's security policy.
Connect Electric
Get your connection string from PlanetScale:
Connection String Requirements
- Use the direct connection (port 5432), not PgBouncer (port 6432)
- Include
sslmode=require(PlanetScale requires SSL/TLS) - See PlanetScale connection strings documentation
docker run -it \
-e "DATABASE_URL=postgresql://electric:secure_password@aws-us-east-1.connect.psdb.cloud:5432/your_db?sslmode=require" \
-p 3000:3000 \
electricsql/electric:latestFOR ALL TABLES Limitation
Some sources suggest PlanetScale doesn't support CREATE PUBLICATION ... FOR ALL TABLES. If you encounter this issue, explicitly list tables in your publication. See Manual Publication Management in the PostgreSQL Permissions guide.
Troubleshooting
For general PostgreSQL permission and configuration errors, see the PostgreSQL Permissions guide.
PlanetScale-Specific Issues
Error: "too many connections"
Cause: Electric's connection pool plus other connections exceed PlanetScale's limit.
Solution: Increase PlanetScale's max_connections to 50+ or reduce ELECTRIC_DB_POOL_SIZE.
Error: "replication slot does not support failover"
Cause: PlanetScale requires failover-enabled replication slots.
Solution: Ensure your cluster has sync_replication_slots = on and hot_standby_feedback = on configured. Electric creates failover-enabled slots automatically.
Best Practices
- Plan connection capacity - Set max_connections to at least 3x Electric's pool size
- Monitor connections - Track connection usage in PlanetScale dashboard
- Use direct connections - Port 5432 (direct), not 6432 (PgBouncer) for replication
- Enable monitoring - Track WAL usage and replication lag in PlanetScale
For general PostgreSQL and Electric best practices, see:
Additional Resources
PlanetScale Documentation:
- PlanetScale for Postgres Quickstart
- Logical Replication and CDC
- Database Settings and Parameters
- Connection Strings
- High Availability with CDC
Electric Documentation: