Restore role ownership when copying LOBs for PG>=17 - #47
Merged
Conversation
On PG17+ pg_dump no longer includes large object metadata in pre-data, so pgcopydb creates the large object itself via lo_create() — leaving it owned by the connecting role instead of its original owner. Restore the owner with ALTER LARGE OBJECT ... OWNER TO after copying, when an owner is known. Ports upstream dimitri/pgcopydb dimitri#1026. Adapted to this repo: upstream gates the ownership restore on a dstIsPG17orLater flag that does not exist here; this repo already tracks whether it created the object via the needsCreate existence check, which is the precise signal (also covers the dropIfExists path), so the restore is gated on needsCreate instead. (cherry picked from commit 53b136a)
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
On PostgreSQL 17+,
pg_dumpno longer includes large object metadata in the pre-data section, so pgcopydb creates each large object itself vialo_create(). That leaves the object owned by the connecting role rather than its original owner. (Fixes upstream issue dimitri#1027.)Fix (ports upstream dimitri/pgcopydb dimitri#1026)
After copying the object contents, run
ALTER LARGE OBJECT … OWNER TO <owner>when an owner is known, restoring the original ownership.PS adaptation: upstream gates this on a
dstIsPG17orLaterflag that doesn't exist in this repo. This repo already tracks whether it created the object itself via theneedsCreateexistence check — which is the precise signal (and also covers thedropIfExistspath) — so the restore is gated onneedsCreateinstead of a raw version check.Tests
Full
PGVERSION=18 make testsgreen (all suites, exit 0). Theblobssuite (with a non-defaultblobownerrole) exercises the ownership path; the cherry-pick brought its test updates.