Skip to main content

Postgres

ElectricSQL requires a PostgreSQL database. Postgres is the world's most advanced open source relational database.

Compatibility

ElectricSQL works with standard Postgres version >= 13.0 with logical replication enabled. Note that you don't need to install any extensions or run any unsafe code.

Hosting

Many managed hosting providers support logical replication (either out of the box or as an option to enable).

This includes, for example:

  • AWS RDS and Aurora (including Aurora Serverless v2)
  • Crunchy Data who have a free tier and logical replication enabled by default

There's a long list of Postgres hosting providers here.

Self-host / run locally

You can run your own Postgres anywhere you like. See the Postgres Server Administration docs for more information.

Docker

For example, to run using Docker:

docker run \
-e "POSTGRES_PASSWORD=..." \
-c "wal_level=logical" \
postgres

Homebrew

To run locally using Homebrew, first install and start the service:

brew install postgresql
brew services start postgresql

Enable logical replication:

psql -U postgres \
-c 'ALTER SYSTEM SET wal_level = logical'
brew services restart postgresql

Verify the wal_level is logical:

psql -U postgres -c 'show wal_level'

Permissions

The Electric sync service currently needs to connect to Postgres as a database user with LOGIN and SUPERUSER permissions.

For example:

CREATE ROLE electric
WITH LOGIN
PASSWORD '...'
SUPERUSER;

Note that we are working to remove the SUPERUSER requirement.

More details on future permissions

In future, the permissions required will be a minimum of:

  • LOGIN
  • REPLICATION

And then either ALL on the database and public schema or at a minimum:

  • CONNECT, CREATE and TEMPORARY on the database
  • CREATE, EXECUTE on ALL and USAGE on the public schema

Plus ALTER DEFAULT PRIVILEGES to grant the same permissions on any new tables in the public schema.

For example, to create an electric user with the necessary permissions:

CREATE ROLE electric
WITH LOGIN
PASSWORD '...'
REPLICATION;

GRANT ALL
ON DATABASE '...'
TO electric;

GRANT ALL
ON ALL TABLES
IN SCHEMA public
TO electric;

ALTER DEFAULT PRIVILEGES
IN SCHEMA public
GRANT ALL
ON TABLES
TO electric;

This will remove the need for SUPERUSER, which will increase the compatibility with hosting providers such as Cloud SQL and AlloyDB that won't grant superuser (or a reduced version like rds_superuser).