Repository navigation
fix: deliver Postgres Changes for partitioned tables published via the partition root - #2488
mandar1045 wants to merge 10 commits into
Conversation
…e partition root With publish_via_partition_root, pg_publication_tables lists only the partitioned table, but wal2json reports each change under the leaf partition holding the row. list_changes built add-tables from that view, so the change was filtered out and never delivered. Watch the leaf partitions of each published table, and report a leaf's change as the table it is published as before apply_rls, like pgoutput does with the same option. Fixes supabase#2487
f52b282 to
0742fae
Compare
# Conflicts: # lib/realtime/tenants/migrations.ex # priv/repo/tenant_db_dump_15.sql # priv/repo/tenant_db_dump_17.sql
The migration was never added to Realtime.Tenants.Migrations, so tenants built from migrations (WALRUS --migrations, mix test tenant DBs) kept the old list_changes and dropped changes from partitions published via the partition root. Register it, move it after the latest shipped migration (20261111120000) so the list stays in version order, and record the version in the tenant DB dumps.
ffd15d9 to
ee6d589
Compare
|
What happens when the parent table has no primary key but the partitions have? Will this cause issues with the RLS check? |
|
And I'm wondering if we first want to set-up a benchmark tool for walrus as this is a significant change 🤔 |
|
The issue is that wal2json sends the partition's PK, so the RLS check runs against the parent using only I'll push a fix to make partitions use the parent's PK. If the parent doesn't have one, it'll return the usual "no primary key" error. I'll also add a walrus test to cover this case. For the benchmark, |
wal2json sends the partition's own primary key. If the parent has no primary key, the RLS check on the parent can match a row with the same id in another partition, so a subscriber could get someone else's row. Use the parent's key instead, which gives the usual no primary key error when there isn't one.
|
Pushed the fix, with a walrus test for it. |
Fixes #2487
With
publish_via_partition_root = true,pg_publication_tableslists only the partitioned table, but wal2json reports each change under the leaf partition that holds the row.list_changesbuiltadd-tablesfrom that view, so the leaf was filtered out and every change was dropped while the client stayedSubscribed.list_changesandlist_changes_syncnow watch the leaf partitions of each published table, and report a leaf's change as the table it's published as beforeapply_rls. That's what pgoutput does with the same option, and it means RLS, column privileges and the payloadtableall use the parent. Withoutpublish_via_partition_rootthe publication already lists the leaves, so nothing changes there.list_changesandlist_changes_syncwith that change onlytenant_schemaand the pg15/pg17 dumpstest_partitioned_table(both settings, both functions, RLS on the parent)