Source Database Setup

Configure your backend database for PowerSync

PowerSync currently supports Postgres as backend database.

Configuring your Postgres database with PowerSync generally involves three tasks:

  • Enable logical replication

  • Create a PowerSync database user

  • Create powersync publication

We have documented steps for some hosting providers:

Supabase

1. Enable logical replication

Supabase has logical replication enabled by default — no action required.

2. Create a PowerSync Database User

It is not currently possible to create a new user on Supabase with replication permissions without contacting their support. Instead, use the default postgres user.

3. Create "powersync" Publication

The postgres user does not have access to create a publication for all tables. Instead, list each table explicitly.

This can also be done on the Supabase dashboard in the database Replication page.

CREATE PUBLICATION powersync FOR TABLE public.lists, public.todos;

AWS RDS

Prerequisites

The instance must be publicly accessible using an IPv4 address.

Access may be restricted to specific IPs if required — see IP Filtering.

1. Enable Logical Replication

Set the rds.logical_replication parameter to 1 in the parameter group for the instance.

2. Create a PowerSync Database User

Create a PowerSync user on Postgres:

-- SQL to create powersync user
CREATE ROLE powersync_role WITH LOGIN PASSWORD 'myhighlyrandompassword';
-- Allow the role to perform replication tasks
GRANT rds_replication TO powersync_role;
-- Set up permissions for the newly created role
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO powersync_role;

For read-only access, only the SELECT privilege is required — INSERT, UPDATE and DELETE can be removed.

To restrict read access to specific tables, explicitly list allowed tables for both the SELECT privilege, and for the publication (as well as for any other publications that may exist).

3. Create "powersync" Publication

-- Create publication to replicate tables. Specify a subset of tables if required.
-- NOTE: this must be named "powersync" at the moment
CREATE PUBLICATION powersync FOR ALL TABLES;
Azure Postgres

PowerSync supports both "Azure Database for PostgreSQL" and "Azure Database for PostgreSQL Flexible Server".

Prerequisites

The database must be accessible on the public internet. Once you have created your database, navigate to Settings -> Networking and enable Public access.

1. Enable Logical Replication

Follow the steps as noted in this article to allow logical replication:

https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-logical#prerequisites-for-logical-replication-and-logical-decoding

2. Create a PowerSync Database User

Create a PowerSync user on Postgres:

-- SQL to create powersync user
CREATE ROLE powersync_role WITH REPLICATION LOGIN PASSWORD 'myhighlyrandompassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO powersync_role;

For read-only access, only the SELECT privilege is required — INSERT, UPDATE and DELETE can be removed.

To restrict read access to specific tables, explicitly list allowed tables for both the SELECT privilege, and for the publication (as well as for any other publications that may exist).

3. Create "powersync" Publication

-- Create publication to replicate tables. Specify a subset of tables if required.
-- NOTE: this must be named "powersync" at the moment
CREATE PUBLICATION powersync FOR ALL TABLES;

-- Example for specifying a subset of tables:
-- CREATE PUBLICATION powersync FOR table users, projects, user_projects, checklists;
Google Cloud SQL

1. Enable Logical Replication

In Google Cloud SQL Postgres, enabling the logical replication is done using flags:

2. Create a PowerSync Database User

Create a PowerSync user on Postgres:

-- SQL to create powersync user
CREATE ROLE powersync_role WITH REPLICATION LOGIN PASSWORD 'myhighlyrandompassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO powersync_role;

For read-only access, only the SELECT privilege is required — INSERT, UPDATE and DELETE can be removed.

To restrict read access to specific tables, explicitly list allowed tables for both the SELECT privilege, and for the publication (as well as for any other publications that may exist).

3. Create "powersync" Publication

-- Create publication to replicate tables. Specify a subset of tables if required.
-- NOTE: this must be named "powersync" at the moment
CREATE PUBLICATION powersync FOR ALL TABLES;
Neon

Neon is a serverless Postgres environment with an innovative pricing model that separates storage and compute.

1. Enable Logical Replication

Open your project and navigate to "Settings" -> "Beta", then click "Enable".

2. Create a PowerSync Database User

Create a PowerSync user on Postgres:

-- SQL to create powersync user
CREATE ROLE powersync_role WITH REPLICATION LOGIN PASSWORD 'myhighlyrandompassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO powersync_role;

For read-only access, only the SELECT privilege is required — INSERT, UPDATE and DELETE can be removed.

To restrict read access to specific tables, explicitly list allowed tables for both the SELECT privilege, and for the publication (as well as for any other publications that may exist).

3. Create "powersync" Publication

-- Create publication to replicate tables. Specify a subset of tables if required.
-- NOTE: this must be named "powersync" at the moment
CREATE PUBLICATION powersync FOR ALL TABLES;
Fly Postgres

Fly Postgres is a Fly app with flyctl sugar on top to help you bootstrap and manage a database cluster for your apps.

1. Enable Logical Replication

Once you've deployed your Fly Postgres cluster, it's time to enable logical replication.

This is performed by running the below command:

fly pg config update --wal-level=logical

2. Create a PowerSync Database User

Create a PowerSync user on Postgres:

-- SQL to create powersync user
CREATE ROLE powersync_role WITH REPLICATION LOGIN PASSWORD 'myhighlyrandompassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO powersync_role;

For read-only access, only the SELECT privilege is required — INSERT, UPDATE and DELETE can be removed.

To restrict read access to specific tables, explicitly list allowed tables for both the SELECT privilege, and for the publication (as well as for any other publications that may exist).

3. Create "powersync" Publication

-- Create publication to replicate tables. Specify a subset of tables if required.
-- NOTE: this must be named "powersync" at the moment
CREATE PUBLICATION powersync FOR ALL TABLES;

For other providers and self-hosted databases:

Other / Self-hosted

Need help? Simply contact us on Discord and we'll help you get set up.

1. Enable Logical Replication

PowerSync reads the Postgres WAL using logical replication in order to create sync buckets in accordance with the specified PowerSync Sync Rules.

If you are managing Postgres yourself, set wal_level = logical in your config file:

Alternatively, you can use the below SQL commands to check and enable logical replication:

-- Check the replication type
SHOW wal_level;

-- Enable logical replication
ALTER SYSTEM SET wal_level = logical;

Note that Postgres must be restarted after changing this config.

If you're using a managed Postgres service, there may be a setting for this in the relevant section of the service's admin console.

2. Create a PowerSync Database User

Create a PowerSync user on Postgres:

-- SQL to create powersync user
CREATE ROLE powersync_role WITH REPLICATION LOGIN PASSWORD 'myhighlyrandompassword';
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO powersync_role;

For read-only access, only the SELECT privilege is required — INSERT, UPDATE and DELETE can be removed.

To restrict read access to specific tables, explicitly list allowed tables for both the SELECT privilege, and for the publication (as well as for any other publications that may exist).

3. Create "powersync" Publication

-- Create publication to replicate tables. Specify a subset of tables if required.
-- NOTE: this must be named "powersync" at the moment
CREATE PUBLICATION powersync FOR ALL TABLES;

Unsupported Hosting Providers

Due to the logical replication requirement, not all hosting providers are supported.

Notably, some "serverless Postgres" providers do not support logical replication, and are therefore not supported by PowerSync yet.

Next Step

Next, connect PowerSync to your database:

Database Connection

Self-hosting

If you are self-hosting PowerSync, refer to PowerSync Service Setup next.

Last updated