pg_ivm
pg_ivm : incremental view maintenance on PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2840 | pg_ivm | pg_ivm | 1.17 |
FEAT | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sLd-- | Yes | Yes | Yes | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | pg_catalog pgivm |
| See Also | pg_incremental pg_trickle timescaledb pg_duckdb pg_partman pg_ttl_index duckdb_fdw pg_lake |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.17 |
18 17 16 15 14 | pg_ivm |
- |
| RPM | PIGSTY | 1.17 |
18 17 16 15 14 | pg_ivm_$v |
- |
| DEB | PIGSTY | 1.17 |
18 17 16 15 14 | postgresql-$v-pg-ivm |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| el8.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| el9.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| el9.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| el10.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| el10.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| d12.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| d12.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| d13.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| d13.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| u22.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| u22.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| u24.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| u24.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| u26.x86_64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
| u26.aarch64 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 | PIGSTY 1.17 |
Source
github.com/sraoss/pg_ivm
pg_ivm-1.17.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
Sources:
pg_ivm provides immediate incremental view maintenance for PostgreSQL. An Incrementally Maintainable Materialized View (IMMV) is stored as a table with triggers and metadata in the pgivm schema; base-table changes update the IMMV inside the same transaction instead of recomputing the complete query.
Enable and Create an IMMV
Load the library for every session that can modify an IMMV’s base tables. A cluster-wide setup requires a restart:
session_preload_libraries = 'pg_ivm' is also supported when managed consistently for all relevant sessions.
Manage and Inspect IMMVs
pgivm.create_immv(name, query): creates and populates an IMMV, returning its row count.pgivm.refresh_immv(name, with_data): fully rebuilds the IMMV;falsedisables maintenance until a later populated refresh.pgivm.get_immv_def(regclass): returns the stored view definition.pgivm.restore_immv(name, query, populate, replace): reconstructs metadata, triggers, and indexes for an existing IMMV table; 1.17 adds the optional replacement flag.pgivm.get_create_immv_commands()andpgivm.get_restore_immv_commands(): emit SQL for rebuilding IMMVs or restoring their metadata.
Version 1.15 includes a helper for dump or pg_upgrade workflows:
The script emits pgivm.restore_immv() calls. Restore the table data first, then execute the saved metadata SQL so incremental maintenance resumes without recreating the tables.
Restrictions and Operational Caveats
- Supported definitions include selected joins,
DISTINCT, simple subqueries/CTEs, and built-incount,sum,avg,min, andmaxaggregates. Unsupported constructs includeHAVING, window functions,ORDER BY,LIMIT/OFFSET, set operations,DISTINCT ON, and user-defined aggregates. - Efficient maintenance depends on a suitable unique index.
create_immv()creates one automatically only when the definition supplies usable grouping, distinct, or base-table primary-key columns. - Creation and refresh take
AccessExclusiveLock. Upstream warns about consistency risks for creation underREPEATABLE READorSERIALIZABLE; useREAD COMMITTEDor refresh afterward. restore_immv()fails on an already registered relation unlessreplace = true; that option requires a superuser. Without replacement the caller must own the IMMV. A table-definition mismatch still fails.- Version 1.15 also fixes incorrect maintenance after repeated trigger-driven modifications and a v1.14 outer-join maintenance crash.
Upgrade to 1.16
Version 1.16 adds PostgreSQL 19 support and fixes a crash when maintaining and dropping an IMMV in one transaction, maintenance involving columns without default equality operators, large OID handling, and maintenance lock-release timing. Install matching files and ensure modifying sessions load the new library, then run:
Upgrade to 1.17
Upstream supports PostgreSQL 13–19. Version 1.17 fixes the restored IMMV population flag, preventing duplicate maintenance triggers after a later refresh; it also improves automatic unique-index derivation, rejects set-returning target lists and fixes index-creation crashes with LATERAL subqueries.
Install matching files, ensure modifying sessions use the new library, then update each database:
For a PostgreSQL major upgrade, put the new option first when exporting metadata before the upgrade:
The generated restore calls replace the old catalog entries left by the major upgrade. Run the saved SQL after completing the upgrade, as a superuser. The IMMV tables and their data must already be present; replacement is not a substitute for restoring the data.