Skip to content

Add pg_upgrade support functions#2326

Merged
MuhammadTahaNaveed merged 1 commit intoapache:masterfrom
jrgemignani:add_pg_upgrade_support
Feb 10, 2026
Merged

Add pg_upgrade support functions#2326
MuhammadTahaNaveed merged 1 commit intoapache:masterfrom
jrgemignani:add_pg_upgrade_support

Conversation

@jrgemignani
Copy link
Contributor

Add pg_upgrade support functions for PostgreSQL major version upgrades

NOTE: This PR was created with AI tools and a human.

The ag_graph.namespace column uses the regnamespace type, which pg_upgrade cannot handle in user tables. This commit adds four SQL functions to enable seamless PostgreSQL major version upgrades while preserving all graph data.

New functions in ag_catalog:

  • age_prepare_pg_upgrade(): Converts namespace from regnamespace to oid, creates backup table with graph-to-namespace mappings
  • age_finish_pg_upgrade(): Remaps stale OIDs after upgrade, restores regnamespace type, invalidates AGE caches
  • age_revert_pg_upgrade_changes(): Cancels preparation if upgrade is aborted
  • age_pg_upgrade_status(): Returns current upgrade readiness status

Usage:

  1. Before pg_upgrade: SELECT age_prepare_pg_upgrade();
  2. Run pg_upgrade as normal
  3. After pg_upgrade: SELECT age_finish_pg_upgrade();

The functions include automatic cache invalidation by touching graph namespaces, ensuring cypher queries work immediately without requiring a session reconnect.

Files changed:

  • sql/age_pg_upgrade.sql: New file with function implementations
  • sql/sql_files: Added age_pg_upgrade entry
  • age--1.7.0--y.y.y.sql: Added functions for extension upgrades

All regressions tests passed.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds PostgreSQL pg_upgrade helper functions to Apache AGE to work around regnamespace being unsupported by pg_upgrade in user tables, enabling major-version upgrades while preserving graph metadata.

Changes:

  • Introduces age_prepare_pg_upgrade(), age_finish_pg_upgrade(), age_revert_pg_upgrade_changes(), and age_pg_upgrade_status() in ag_catalog.
  • Registers the new SQL file in the extension build/install process.
  • Adds the same functions to the extension upgrade script for 1.7.0 -> y.y.y.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 17 comments.

File Description
sql/sql_files Adds the new age_pg_upgrade SQL script to the extension SQL composition list.
sql/age_pg_upgrade.sql Implements the four pg_upgrade support functions (prepare/finish/revert/status).
age--1.7.0--y.y.y.sql Adds the same functions to the extension upgrade path script.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add pg_upgrade support functions for PostgreSQL for major version
upgrades

NOTE: This PR was created with AI tools and a human.

The ag_graph.namespace column uses the regnamespace type, which pg_upgrade
cannot handle in user tables. This commit adds four SQL functions to enable
seamless PostgreSQL major version upgrades while preserving all graph data.

New functions in ag_catalog:
- age_prepare_pg_upgrade(): Converts namespace from regnamespace to oid,
  creates backup table with graph-to-namespace mappings (stores nspname
  directly to avoid quoting issues)
- age_finish_pg_upgrade(): Remaps stale OIDs after upgrade, restores
  regnamespace type, invalidates AGE caches while preserving schema ownership
- age_revert_pg_upgrade_changes(): Cancels preparation if upgrade is aborted
- age_pg_upgrade_status(): Returns current upgrade readiness status

Usage:
  1. Before pg_upgrade: SELECT age_prepare_pg_upgrade();
  2. Run pg_upgrade as normal
  3. After pg_upgrade:  SELECT age_finish_pg_upgrade();

Key implementation details:
- Uses transaction-level advisory locks (pg_advisory_xact_lock) for safety
- Preserves original schema ownership during cache invalidation
- Validates all backup rows are mapped before proceeding
- Handles zero-graph edge case gracefully
- Handles insufficient privileges gracefully with informative notices
- Backup table deleted only after all steps succeed

Files changed:
- sql/age_pg_upgrade.sql: New file with function implementations
- sql/sql_files: Added age_pg_upgrade entry
- age--1.7.0--y.y.y.sql: Added functions for extension upgrades

All regression tests pass.
@jrgemignani jrgemignani force-pushed the add_pg_upgrade_support branch from 9f81dd6 to bddb837 Compare February 10, 2026 18:26
@MuhammadTahaNaveed MuhammadTahaNaveed merged commit 5fe2121 into apache:master Feb 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

master override-stale To keep issues/PRs untouched from stale action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants