Skip to content

Restore role ownership when copying LOBs for PG>=17 - #47

Merged
teknogeek0 merged 1 commit into
mainfrom
fix/lob-ownership-pg17
Jul 23, 2026
Merged

Restore role ownership when copying LOBs for PG>=17#47
teknogeek0 merged 1 commit into
mainfrom
fix/lob-ownership-pg17

Conversation

@teknogeek0

Copy link
Copy Markdown
Collaborator

Problem

On PostgreSQL 17+, pg_dump no longer includes large object metadata in the pre-data section, so pgcopydb creates each large object itself via lo_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 dstIsPG17orLater flag that doesn't exist in this repo. This repo already tracks whether it created the object itself via the needsCreate existence check — which is the precise signal (and also covers the dropIfExists path) — so the restore is gated on needsCreate instead of a raw version check.

Tests

Full PGVERSION=18 make tests green (all suites, exit 0). The blobs suite (with a non-default blobowner role) exercises the ownership path; the cherry-pick brought its test updates.

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)
@teknogeek0
teknogeek0 merged commit 43735a8 into main Jul 23, 2026
93 checks passed
@teknogeek0
teknogeek0 deleted the fix/lob-ownership-pg17 branch July 23, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants