Repository navigation
Dump an extension-member foreign server a foreign table depends on - #128
Closed
talmacschen-arch wants to merge 1 commit into
Closed
talmacschen-arch wants to merge 1 commit into
talmacschen-arch wants to merge 1 commit into
Conversation
GetForeignServers skips any foreign server that belongs to an extension
(pg_depend deptype 'e'), on the assumption that CREATE EXTENSION recreates it.
But gpbackup still dumps the user's foreign tables, which are not extension
members. When a dumped foreign table depends on an extension-member server --
for example a migration tool registered the server under the FDW extension
with ALTER EXTENSION ... ADD SERVER -- the server is omitted from the backup
and the foreign table cannot be restored:
ERROR: server "..." does not exist
Also dump an extension-member server when a to-be-dumped foreign table depends
on it, so the backup stays self-contained. A server that no dumped foreign
table references stays filtered, so genuinely extension-internal servers are
still skipped and not recreated twice on restore.
Add an integration test asserting a referenced extension-member server is
returned while an unreferenced one is not.
Author
|
Closing in favor of #129. Investigation with an end-to-end test showed the root cause is not |
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
Restoring a database that contains foreign tables aborts their creation:
The backup's
metadata.sqlcontains theCREATE FOREIGN TABLEstatements but noCREATE SERVERfor the servers they reference, so every such foreign table (and itsALTER FOREIGN TABLE ... OWNER) fails on restore.Root cause
GetForeignServersfilters withExtensionFilterClause, i.e. it skips any foreign server that is an extension member (pg_dependdeptype'e'), on the assumption thatCREATE EXTENSIONwill recreate it. A freshly created server is deptype'n'and is kept — but a server that was added to an FDW extension withALTER EXTENSION <fdw> ADD SERVERbecomes deptype'e'and is dropped from the dump. This is how the affected servers were created (a migration tool registered them under the FDW extension). Their foreign tables are ordinary objects (deptype'n') and are still dumped, leaving the backup inconsistent: a dumped foreign table whose server was silently skipped cannot be restored.Reproduced deterministically: a server is kept until
ALTER EXTENSION ... ADD SERVER, after whichoid NOT IN (pg_depend where deptype='e')becomes false and gpbackup omits it.Fix
Also dump an extension-member server when a to-be-dumped foreign table depends on it, so the backup is self-contained. A server that no dumped foreign table references stays filtered, so genuinely extension-internal servers are still skipped and are not created twice on restore (no
already exists).Scope note:
GetUserMappingswas considered for the same treatment but left unchanged — a user mapping cannot be made an extension member (ALTER EXTENSION ... ADD USER MAPPINGis a syntax error), so thedeptype='e'clause never filters one in practice, and the affected backup contained no user mappings.Note — is this gpbackup's bug?
Arguably the root cause is upstream: a migration tool should not
ALTER EXTENSION ADD SERVERa server that user foreign tables depend on, since that makes the server undumpable; andpg_dumplikewise skips extension-member objects, so by that standard gpbackup's old behavior is "not wrong". This PR takes the pragmatic position that a backup which dumps a foreign table must also dump the server that table needs, rather than produce an unrestorable backup. It only pulls in servers an exported foreign table actually references, so it does not broaden extension handling in general.Testing
Added an integration test in the
GetForeignServersblock: a server added to an extension and referenced by a foreign table is returned, while an extension-member server that nothing references is not.