pg_ivm
pg_ivm : incremental view maintenance on PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2840 | pg_ivm
|
pg_ivm
|
1.14 |
FEAT
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd--
|
No
|
Yes
|
Yes
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Schemas | pg_catalog |
| See Also | age
hll
rum
pg_graphql
pg_jsonschema
jsquery
pg_hint_plan
|
deb takeover by pgdg since 2026-01
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED
|
1.14 |
18
17
16
15
14
|
pg_ivm |
- |
| RPM | PIGSTY
|
1.14 |
18
17
16
15
14
|
pg_ivm_$v |
- |
| DEB | PIGSTY
|
1.14 |
18
17
16
15
14
|
postgresql-$v-pg-ivm |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
el8.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
el9.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
el9.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
el10.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
el10.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
d12.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
d12.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
d13.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
d13.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
u22.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
u22.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
u24.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
u24.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
u26.x86_64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
u26.aarch64
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
PIGSTY 1.14
|
Source
pig build pkg pg_ivm; # build debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_ivm; # install via package name, for the active PG version
pig install pg_ivm -v 18; # install for PG 18
pig install pg_ivm -v 17; # install for PG 17
pig install pg_ivm -v 16; # install for PG 16
pig install pg_ivm -v 15; # install for PG 15
pig install pg_ivm -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_ivm';Create this extension with:
CREATE EXTENSION pg_ivm;Usage
Sources: README, release 1.14
pg_ivm provides immediate Incremental View Maintenance for PostgreSQL materialized views. Instead of recomputing the whole view, it applies deltas in AFTER triggers and stores metadata in the pgivm schema.
CREATE EXTENSION pg_ivm;Required Setup
Upstream says pg_ivm should be preloaded so IMMVs are maintained correctly:
shared_preload_libraries = 'pg_ivm'
session_preload_libraries = 'pg_ivm'The current README says the extension is compatible with PostgreSQL 13 through 18, and the latest GitHub release is 1.14 dated March 31, 2026.
Main Functions
pgivm.create_immv(name, query)creates an incrementally maintainable materialized view (IMMV), its maintenance triggers, and a unique index when possible.pgivm.refresh_immv(name, with_data)fully refreshes the IMMV and can disable or re-enable maintenance.pgivm.get_immv_def(regclass)reconstructs the storedSELECTdefinition.pgivm.pg_ivm_immvstores IMMV metadata includingimmvrelid,viewdef,ispopulated, andlastivmupdate.
Common Patterns
Create an IMMV:
SELECT pgivm.create_immv(
'immv_agg',
'SELECT bid, count(*), sum(abalance), avg(abalance)
FROM pgbench_accounts JOIN pgbench_branches USING(bid)
GROUP BY bid'
);Query the maintained result after base-table changes:
UPDATE pgbench_accounts SET abalance = abalance + 1000 WHERE aid = 4112345;
SELECT * FROM immv_agg WHERE bid = 42;Inspect or refresh IMMVs:
SELECT immvrelid AS immv, pgivm.get_immv_def(immvrelid)
FROM pgivm.pg_ivm_immv;
SELECT pgivm.refresh_immv('immv_agg', true);Pause maintenance for bulk work, then rebuild:
SELECT pgivm.refresh_immv('myview', false);
-- bulk changes
SELECT pgivm.refresh_immv('myview', true);Caveats
- Upstream only supports a restricted subset of view definitions: joins,
DISTINCT, simple subqueries/CTEs, and built-in aggregatescount,sum,avg,min, andmax. - Unsupported constructs include
HAVING, window functions,ORDER BY,LIMIT/OFFSET,UNION/INTERSECT/EXCEPT,DISTINCT ON, and user-defined aggregates. - Efficient maintenance depends on having a suitable unique index;
create_immvcreates one automatically only when the definition allows it.