Skip to content

[#31938] YSQL: MAGE extension does work in backup/restore scenarios#31981

Open
shubin-yb wants to merge 4 commits into
yugabyte:masterfrom
shubin-yb:mage
Open

[#31938] YSQL: MAGE extension does work in backup/restore scenarios#31981
shubin-yb wants to merge 4 commits into
yugabyte:masterfrom
shubin-yb:mage

Conversation

@shubin-yb

@shubin-yb shubin-yb commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

DO NOT MERGE!! CSI

sql_dump in binary-upgrade mode emits

DROP EXTENSION IF EXISTS mage;

before recreating an empty extension shell, so any backup/restore of a database that uses the mage (Apache AGE) extension hits this statement during restore. The mage ProcessUtility hook intercepts every DROP that mentions "mage" via is_age_drop() and unconditionally routes it through drop_age_extension(), which enumerates graphs from mag_catalog.ag_graph. When the extension is not (yet) installed on the restore target, that lookup errors out with

ERROR:  table "ag_graph" does not exist

and the whole restore aborts, so a backup of a mage-using database was effectively unrestorable.

Fix: guard is_age_drop() with get_extension_oid("mage", true). When the extension is not installed, defer to standard ProcessUtility, which correctly performs the IF EXISTS no-op (or raises the standard "extension does not exist" error for a bare DROP EXTENSION mage). get_extension_oid is preferred over checking the mag_catalog schema: the schema can linger after a prior DROP EXTENSION (so a schema-based guard still ran the AGE drop path and still hit the ag_graph lookup).

Tests:

  • src/postgres/third-party-extensions/mage/regress/{sql,expected}/ yb.orig.basic.{sql,out}: three direct regress cases appended at the end of the existing yb.orig.basic test: - DROP EXTENSION IF EXISTS mage; when not installed -> NOTICE skip

    • DROP EXTENSION mage; when not installed -> proper
      "extension does not exist" error, not the ag_graph one
    • CREATE EXTENSION mage; then DROP EXTENSION IF EXISTS mage;
      confirms the AGE cleanup path still runs when installed
  • java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbBackup.java: testMageBackupRestore does an end-to-end YBC backup/restore round trip on a database with mage installed Adds a class-level ysql_yb_enable_mage=true tserver flag; harmless to the other tests in the class, which never CREATE EXTENSION mage.

Verified locally on a 3-node mini-cluster:

  • mage regress (TestPgRegressThirdPartyExtensionsMage): 1/1 pass.
  • TestYbBackup#testMageBackupRestore under YB_TEST_YB_CONTROLLER=1:

@shubin-yb shubin-yb requested a review from hari90 June 1, 2026 20:27

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where dropping the mage extension when it is not installed causes an error, which broke backup/restore operations. It adds a check in is_age_drop to verify if the extension is installed before proceeding with the AGE-specific drop path, and includes corresponding regression and integration tests. The reviewer suggested wrapping the test logic in TestYbBackup.java within a try-finally block to ensure robust cleanup of the database and extension in case of test failures, preventing test pollution.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbBackup.java
@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploy Preview for infallible-bardeen-164bc9 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit dc9d294
🔍 Latest deploy log https://app.netlify.com/projects/infallible-bardeen-164bc9/deploys/6a1def92af87d70008806f9a
😎 Deploy Preview https://deploy-preview-31981--infallible-bardeen-164bc9.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@shubin-yb shubin-yb changed the title [#31938]: MAGE extension does work in backup/restore scenarios [#31938] YSQL: MAGE extension does work in backup/restore scenarios Jun 1, 2026
shubin-yb added 2 commits June 1, 2026 20:45
sql_dump in binary-upgrade mode emits

    DROP EXTENSION IF EXISTS mage;

before recreating an empty extension shell, so any backup/restore of a
database that uses the mage (Apache AGE) extension hits this statement
during restore. The mage ProcessUtility hook intercepts every DROP that
mentions "mage" via is_age_drop() and unconditionally routes it through
drop_age_extension(), which enumerates graphs from mag_catalog.ag_graph.
When the extension is not (yet) installed on the restore target, that
lookup errors out with

    ERROR:  table "ag_graph" does not exist

and the whole restore aborts, so a backup of a mage-using database was
effectively unrestorable.

Fix: guard is_age_drop() with get_extension_oid("mage", true). When the
extension is not installed, defer to standard ProcessUtility, which
correctly performs the IF EXISTS no-op (or raises the standard
"extension does not exist" error for a bare DROP EXTENSION mage).
get_extension_oid is preferred over checking the mag_catalog schema:
the schema can linger after a prior DROP EXTENSION (so a schema-based
guard still ran the AGE drop path and still hit the ag_graph lookup).

Tests:

  * src/postgres/third-party-extensions/mage/regress/{sql,expected}/
    yb.orig.basic.{sql,out}: three direct regress cases appended at the
    end of the existing yb.orig.basic test:
      - DROP EXTENSION IF EXISTS mage; when not installed -> NOTICE skip
      - DROP EXTENSION mage; when not installed           -> proper
        "extension does not exist" error, not the ag_graph one
      - CREATE EXTENSION mage; then DROP EXTENSION IF EXISTS mage;
        confirms the AGE cleanup path still runs when installed

  * java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbBackup.java:
    testMageBackupRestore does an end-to-end YBC backup/restore round
    trip on a database with mage installed
    Adds a class-level ysql_yb_enable_mage=true tserver flag; harmless
    to the other tests in the class, which never CREATE EXTENSION mage.

Verified locally on a 3-node mini-cluster:
  * mage regress (TestPgRegressThirdPartyExtensionsMage): 1/1 pass.
  * TestYbBackup#testMageBackupRestore under YB_TEST_YB_CONTROLLER=1:
@shubin-yb

Copy link
Copy Markdown
Contributor Author

trigger jenkins

@yb-agentk-dev

yb-agentk-dev Bot commented Jun 1, 2026

Copy link
Copy Markdown

Jenkins build has been triggered. Results will be available in the CI checks. CSI

@hari90 hari90 requested a review from HarshDaryani896 June 1, 2026 21:31

@karthik-ramanathan-3006 karthik-ramanathan-3006 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.
Wouldn't this also be a problem for upstream Apache AGE?
Would it be worth contributing an upstream fix? Or have they already fixed it?

Comment thread src/postgres/third-party-extensions/mage/src/backend/catalog/ag_catalog.c Outdated
Comment thread src/postgres/third-party-extensions/mage/src/backend/catalog/ag_catalog.c Outdated
Comment thread java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbBackup.java Outdated
Comment thread java/yb-pgsql/src/test/java/org/yb/pgsql/TestYbBackup.java
shubin-yb and others added 2 commits June 11, 2026 08:08
Co-authored-by: Karthik Ramanathan <32414766+karthik-ramanathan-3006@users.noreply.github.com>
@shubin-yb

Copy link
Copy Markdown
Contributor Author

trigger jenkins

@yb-agentk-dev

yb-agentk-dev Bot commented Jun 11, 2026

Copy link
Copy Markdown

Jenkins build has been triggered. Results will be available in the CI checks. CSI

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