Check publication privileges before creating one - #59
Open
teknogeek0 wants to merge 1 commit into
Open
Conversation
CREATE PUBLICATION needs CREATE on the database and ownership of every published table. Many managed Postgres services grant neither to a migration role, so pgcopydb failed mid-run with a bare permission error. Check both up front and report the ways forward: grant the privilege, pre-create the publication and pass --publication, or use wal2json. Ownership uses pg_has_role(), so role membership counts. Also fail when the table list is empty, instead of creating a publication that decodes no change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
--plugin pgoutput(the default since #58), pgcopydb creates its own publication.CREATE PUBLICATIONneedsCREATEon the database, andCREATE PUBLICATION ... FOR TABLEneeds ownership of every published table. Managed Postgres services often grant neither to a migration role.The run failed mid-flight with a bare server error and no guidance:
Change
Check both privileges before the DDL and report every way forward in one pass:
Both causes are reported together, so fixing one does not reveal the other on the next run.
pg_has_role(current_user, c.relowner, 'USAGE'), matching the server's own check, so membership in the owning role counts and superusers pass.publication_append_table_query(), shared by the check and theCREATE. The check counts exactly the tables the publication would list, filters included.CREATE PUBLICATION "pgcopydb"with noFOR TABLE, which decodes no change at all. It now fails with an explanation.No CLI or docs change.
Test
New
tests/pgoutput-privilegessuite, four phases:CREATE, no ownership: fails, reports both causes and all three options, leaves no publication or slot behind.CREATEgranted, ownership missing: fails, reports only ownership.--publicationgiven: used as-is, pgcopydb creates none of its own.Added to
tests/Makefileand the CI integration matrix.Results
Full PG18 suite run locally. All suites pass except
exclude-extension, which is a pre-existing failure unrelated to this change:tests/exclude-extension/Dockerfile:1defaultsPGCOPYDB_IMAGEtopgcopydb:pg16and its compose file passes no build arg, so it only works on PG16. It is not in the CI matrix.Style check passes (
citus_indent --check).