Sharding is often used in Postgres to handle higher data volumes.
PowerSync cannot replicate foreign tables, but does have other options available to support sharded databases.
The primary options are:
- 1.Use a separate PowerSync instance per database.
- 2.Add a connection for each database in the same PowerSync instance.
Where feasible, using separate PowerSync instances would give better performance and give more control over how changes are rolled out, especially around sync rule reprocessing.
Some specific scenarios:
This is common when separate "services" use separate databases, but multiple tables across those databases need to be synchronized to the same users.
This is common when sharding per customer account / organization.
In this case, use a separate PowerSync instance for each database.
If the amount of shared data is small, still use a separate PowerSync instance for each database, but also add the shared database connection to each PowerSync instance using a separate connection tag.
In some cases, most tables would be on a shared server, with only a few large tables being sharded.
For this case, use a single PowerSync instance. Add each shard as a new connection on this instance — all with the same connection tag, so that the same sync rules applies to each.