Skip to main content

Schemas (Postgres)

When no schema is specified, the Postgres public schema is used for every query. A different schema can be specified as a prefix:

Schemas (SQL Server)

When no schema is specified, the dbo schema is used. To use a table from another schema in the same database, prefix it with the schema name.
Wildcards are not supported in SQL Server schema or table names, so list each table separately. If a query uses a wildcard, replication fails with PSYNC_R2201. On self-hosted instances, the connection’s schema option changes the default schema. The _powersync_checkpoints table must be in that schema too.

Multiple Databases (MySQL and MongoDB)

A MySQL or MongoDB connection can replicate from several databases on the same MySQL server or MongoDB cluster. Tables without a prefix come from the database in the connection settings. To use a table from another database, prefix it with the database name.
If a name needs quotes, use double quotes, such as "inventory"."assets". MySQL backticks are not supported. Rows sync to a client-side table named after the source table, without the database name. If two databases have a table with the same name, rows from both sync to the same client-side table. To keep them apart, give one of them an alias.
The database name can’t contain a wildcard, so list each database separately. If a query uses a wildcard such as "tenant_%".orders, replication fails with PSYNC_R2201. For MySQL, grant the database user SELECT on each database you use, as described in Database User Configuration. For MongoDB, read access on each database is not enough. Once a query uses a second database, PowerSync reads changes from the whole cluster, so the user needs read access on the entire cluster. With Post Images set to Auto-Configure, the default for new instances, the user also needs dbAdmin on each database. See MongoDB Permissions. A Postgres or SQL Server connection replicates from one database, and the prefix there is a schema in that database. For databases on separate servers or clusters, see Multiple Separate Database Connections.

Wildcard Schemas (Postgres)

Wildcard schemas require Sync Streams and PowerSync Service v1.24.0 or later. They are currently only supported for Postgres connections.
Use % as a wildcard in the schema name to match tables with the same name across multiple schemas. "%" matches every schema, and a prefix such as "tenant_%" matches every schema whose name starts with tenant_. The wildcard can only be the last character of the schema name. Postgres system schemas (pg_* and information_schema) are never matched. Combine a wildcard schema with the schema() function, which returns the schema each row was replicated from, to filter rows by schema. This supports schema-per-tenant databases (a single database with one identical schema per tenant): one stream covers every tenant schema, and each client syncs only its own tenant’s data, resolved from a JWT claim.
In this example, rows are grouped into a bucket per schema, and each client syncs only the bucket matching the tenant_schema claim in its JWT. Rows from all matched schemas sync into a single client-side table, named after the table in the query (work_orders here).
Each matched table must be part of the PowerSync publication. Tables that are not in the publication are skipped.

High Availability / Replicated Databases (Postgres)

When the source Postgres database is replicated, for example with Amazon RDS Multi-AZ deployments, specify a single connection with multiple host endpoints. Each host endpoint will be tried in sequence, with the first available primary connection being used. For this, each endpoint must point to the same physical database, with the same replication slots. This is the case when block-level replication is used between the databases, but not when streaming physical or logical replication is used. In those cases, replication slots are unique on each host, and all data would be re-synced in a fail-over event. On Postgres 17 or later, PowerSync can keep its replication slots through a failover to a physical standby. See Replication Slot Failover.

Multiple Separate Database Connections (Planned)

This feature will be available in a future release. See this item on our roadmap.
In the future, it will be possible to configure PowerSync with multiple separate source database connections, where each connection is concurrently replicated. You should not add multiple connections to multiple replicas of the same database — this would cause data duplication. Only use this when the data on each connection does not overlap. It will be possible for each connection to be configured with a “tag”, to distinguish these connections in sync queries. The same tag may be used for multiple connections (if the schema is the same in each). By default, queries will reference the “default” tag. To use a different connection or connections, assign a different tag, and specify it in the query as a schema prefix. In this case, the schema itself must also be specified.