pg_ivm
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_ivm | 1.15 | FEAT | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2840 | pg_ivm | No | Yes | Yes | Yes | No | No | pg_catalog |
PGDG RPM and PIGSTY DEB are aligned at 1.15 for PostgreSQL 14-18.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 1.15 | 1817161514 | pg_ivm | - |
| RPM | PGDG | 1.15 | 1817161514 | pg_ivm_$v | - |
| DEB | PIGSTY | 1.15 | 1817161514 | postgresql-$v-pg-ivm | - |
Build
You can build the DEB packages for pg_ivm using pig build:
Install
You can install pg_ivm directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Create Extension:
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): version 1.15 function that reconstructs metadata, triggers, and indexes for an existing IMMV table.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 when the relation is already registered or its table definition does not match the supplied query.- Version 1.15 also fixes incorrect maintenance after repeated trigger-driven modifications and a v1.14 outer-join maintenance crash.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)