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
- Table ownership - The database user Electric connects as must own the tables it syncs
For general PostgreSQL user and permission setup, see the PostgreSQL Permissions guide.
Table ownership is critical
On PlanetScale, you typically cannot transfer table ownership after the fact. Run your database migrations using the same database user that Electric connects as, so that user owns the tables from the start. See Table Ownership below.
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=10Table Ownership
Electric needs to own the tables it syncs in order to add them to publications and set REPLICA IDENTITY FULL. On PlanetScale, the default role cannot run ALTER TABLE ... OWNER TO, so you cannot transfer ownership after tables are created.
Run your migrations as the same database user that Electric will connect as. This way, that user owns the tables from the start and Electric can manage them automatically.
For example, if your PlanetScale connection string uses postgres.abc123:
# Use the same user for migrations that Electric will connect as
DATABASE_URL=postgresql://postgres.abc123:password@host:5432/db npx prisma migrate deployAlready have tables owned by a different user?
If your tables were created by a different user and you can't transfer ownership (common on PlanetScale), you have three options:
- Reassign objects in PlanetScale Console — go to your database role's menu (three dots) and select "Reassign objects" to transfer table ownership from the old migration role to the Electric user
- Re-create the tables using the correct user by running your migrations with the Electric user's credentials
- Use Manual Mode — set
ELECTRIC_MANUAL_TABLE_PUBLISHING=trueand have an admin pre-configure the publication and replica identity. See Manual Mode in the PostgreSQL Permissions guide.
Database User Setup
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 for both migrations and Electric's connection. If you create a dedicated replication role instead, make sure to also run your migrations as that role so it owns the tables.
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 Table Ownership for user requirements
- See PlanetScale connection strings documentation
Using Electric Cloud
The simplest way to connect is via Electric Cloud. Use the direct connection string (port 5432) with sslmode=require. The database user must be the same one that ran your migrations (see Table Ownership).
Self-hosted
docker run -it \
-e "DATABASE_URL=postgresql://postgres.abc123:[email protected]:5432/your_db?sslmode=require" \
-p 3000:3000 \
electricsql/electric:latestFOR ALL TABLES Limitation
PlanetScale requires tables to be added to publications individually and does not 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: "must be owner of table"
Cause: The database user Electric connects as does not own the table. This commonly happens when tables were created by a different user than the one Electric is using.
Solution: Run your migrations as the same database user that Electric connects as. See Table Ownership for details, or use Manual Mode (ELECTRIC_MANUAL_TABLE_PUBLISHING=true) if you cannot re-run migrations.
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: