Databases & Storage

pg_ivm 1.17 brings pg_upgrade support, fixes IMMV restore bugs

Key Takeaway

pg_ivm 1.17 adds a replace option for IMMV restoration and a --pg-upgrade flag for metadata dumps, while fixing bugs that caused duplicate triggers and crashes with LATERAL subqueries.

Summary

The IVM Development Group has released pg_ivm 1.17, an update to the PostgreSQL extension that enables Incremental View Maintenance for materialized views. This version introduces operational improvements for database migrations and backup recovery, specifically a replace option in restore_immv() and a --pg-upgrade option for pg_ivm_dump_metadata that generates compatible restore commands. Previously, restoring IMMVs after pg_upgrade failed because stale metadata entries persisted in pg_ivm_immv.

The release also addresses several correctness and stability issues. A bug where restore_immv() left ispopulated = false could cause subsequent refresh_immv() calls to install duplicate IVM triggers, leading to incorrect view maintenance. Unique key derivation for automatic index creation now works from original view definitions rather than rewritten queries, enabling index creation for EXISTS clauses and properly rejecting set-returning functions. Two crash conditions—one during index creation with LATERAL subqueries and another assertion failure in check_immv_compatibility()—are also resolved.

What's new in pg_ivm 1.17

  • restore_immv() replace option: The function now accepts a replace parameter that overwrites existing IMMV metadata entries, eliminating restoration failures caused by stale pg_ivm_immv records.
  • pg_upgrade metadata support: pg_ivm_dump_metadata gains a --pg-upgrade flag that emits restore commands compatible with PostgreSQL's pg_upgrade tooling, addressing a previously broken post-upgrade workflow.
  • ispopulated state fix: restore_immv() now correctly sets ispopulated = true; the previous false state caused refresh_immv() to append duplicate IVM triggers, corrupting incremental maintenance.
  • Stability fixes: Two crash paths are closed—index creation with LATERAL subqueries and an assertion failure in check_immv_compatibility()—and error messages for failed automatic index creation are generalized.

Why it matters

For PostgreSQL administrators running materialized views at scale, pg_ivm 1.17 removes a significant operational blocker: IMMVs can now survive major version upgrades through pg_upgrade without manual metadata cleanup. The correctness fixes for trigger duplication and unique-key derivation reduce silent data consistency risks in production workloads that rely on immediate incremental maintenance.

Original reference: www.postgresql.org →