Skip to content
pg_ivm

pg_ivm

pg_ivm : incremental view maintenance on PostgreSQL

Overview

ID Extension Package Version Category License Language
2840
pg_ivm
pg_ivm
1.15
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

PGDG RPM and PIGSTY DEB are aligned at 1.15 for PostgreSQL 14-18.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
1.15
18
17
16
15
14
pg_ivm -
RPM
PGDG
1.15
18
17
16
15
14
pg_ivm_$v -
DEB
PIGSTY
1.15
18
17
16
15
14
postgresql-$v-pg-ivm -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
el8.aarch64
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
el9.x86_64
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
el9.aarch64
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
el10.x86_64
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
el10.aarch64
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
PGDG 1.15
d12.x86_64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
d12.aarch64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
d13.x86_64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
d13.aarch64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
u22.x86_64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
u22.aarch64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
u24.x86_64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
u24.aarch64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
u26.x86_64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
u26.aarch64
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
PIGSTY 1.15
Package Version OS ORG SIZE File URL
pg_ivm_18 1.15 el8.x86_64 pgdg 52.4 KiB pg_ivm_18-1.15-1PGDG.rhel8.10.x86_64.rpm
pg_ivm_18 1.14 el8.x86_64 pigsty 57.9 KiB pg_ivm_18-1.14-1PIGSTY.el8.x86_64.rpm
pg_ivm_18 1.14 el8.x86_64 pgdg 50.3 KiB pg_ivm_18-1.14-1PGDG.rhel8.10.x86_64.rpm
pg_ivm_18 1.13 el8.x86_64 pgdg 49.5 KiB pg_ivm_18-1.13-1PGDG.rhel8.x86_64.rpm
pg_ivm_18 1.12 el8.x86_64 pgdg 43.3 KiB pg_ivm_18-1.12-1PGDG.rhel8.x86_64.rpm
pg_ivm_18 1.15 el8.aarch64 pgdg 50.0 KiB pg_ivm_18-1.15-1PGDG.rhel8.10.aarch64.rpm
pg_ivm_18 1.14 el8.aarch64 pigsty 55.9 KiB pg_ivm_18-1.14-1PIGSTY.el8.aarch64.rpm
pg_ivm_18 1.14 el8.aarch64 pgdg 48.1 KiB pg_ivm_18-1.14-1PGDG.rhel8.10.aarch64.rpm
pg_ivm_18 1.13 el8.aarch64 pgdg 47.5 KiB pg_ivm_18-1.13-1PGDG.rhel8.aarch64.rpm
pg_ivm_18 1.12 el8.aarch64 pgdg 41.2 KiB pg_ivm_18-1.12-1PGDG.rhel8.aarch64.rpm
pg_ivm_18 1.15 el9.x86_64 pgdg 52.0 KiB pg_ivm_18-1.15-1PGDG.rhel9.8.x86_64.rpm
pg_ivm_18 1.14 el9.x86_64 pigsty 57.5 KiB pg_ivm_18-1.14-1PIGSTY.el9.x86_64.rpm
pg_ivm_18 1.14 el9.x86_64 pgdg 49.6 KiB pg_ivm_18-1.14-1PGDG.rhel9.8.x86_64.rpm
pg_ivm_18 1.14 el9.x86_64 pgdg 49.7 KiB pg_ivm_18-1.14-1PGDG.rhel9.7.x86_64.rpm
pg_ivm_18 1.14 el9.x86_64 pgdg 49.7 KiB pg_ivm_18-1.14-1PGDG.rhel9.6.x86_64.rpm
pg_ivm_18 1.13 el9.x86_64 pgdg 49.3 KiB pg_ivm_18-1.13-1PGDG.rhel9.x86_64.rpm
pg_ivm_18 1.12 el9.x86_64 pgdg 43.3 KiB pg_ivm_18-1.12-1PGDG.rhel9.x86_64.rpm
pg_ivm_18 1.15 el9.aarch64 pgdg 50.8 KiB pg_ivm_18-1.15-1PGDG.rhel9.8.aarch64.rpm
pg_ivm_18 1.14 el9.aarch64 pigsty 56.3 KiB pg_ivm_18-1.14-1PIGSTY.el9.aarch64.rpm
pg_ivm_18 1.14 el9.aarch64 pgdg 48.3 KiB pg_ivm_18-1.14-1PGDG.rhel9.8.aarch64.rpm
pg_ivm_18 1.14 el9.aarch64 pgdg 48.3 KiB pg_ivm_18-1.14-1PGDG.rhel9.7.aarch64.rpm
pg_ivm_18 1.14 el9.aarch64 pgdg 48.4 KiB pg_ivm_18-1.14-1PGDG.rhel9.6.aarch64.rpm
pg_ivm_18 1.13 el9.aarch64 pgdg 48.1 KiB pg_ivm_18-1.13-1PGDG.rhel9.aarch64.rpm
pg_ivm_18 1.12 el9.aarch64 pgdg 42.0 KiB pg_ivm_18-1.12-1PGDG.rhel9.aarch64.rpm
pg_ivm_18 1.15 el10.x86_64 pgdg 53.3 KiB pg_ivm_18-1.15-1PGDG.rhel10.2.x86_64.rpm
pg_ivm_18 1.14 el10.x86_64 pigsty 58.5 KiB pg_ivm_18-1.14-1PIGSTY.el10.x86_64.rpm
pg_ivm_18 1.14 el10.x86_64 pgdg 50.8 KiB pg_ivm_18-1.14-1PGDG.rhel10.2.x86_64.rpm
pg_ivm_18 1.14 el10.x86_64 pgdg 50.8 KiB pg_ivm_18-1.14-1PGDG.rhel10.1.x86_64.rpm
pg_ivm_18 1.14 el10.x86_64 pgdg 51.2 KiB pg_ivm_18-1.14-1PGDG.rhel10.0.x86_64.rpm
pg_ivm_18 1.13 el10.x86_64 pgdg 50.6 KiB pg_ivm_18-1.13-1PGDG.rhel10.x86_64.rpm
pg_ivm_18 1.12 el10.x86_64 pgdg 44.1 KiB pg_ivm_18-1.12-1PGDG.rhel10.x86_64.rpm
pg_ivm_18 1.15 el10.aarch64 pgdg 52.1 KiB pg_ivm_18-1.15-1PGDG.rhel10.2.aarch64.rpm
pg_ivm_18 1.14 el10.aarch64 pigsty 57.4 KiB pg_ivm_18-1.14-1PIGSTY.el10.aarch64.rpm
pg_ivm_18 1.14 el10.aarch64 pgdg 49.5 KiB pg_ivm_18-1.14-1PGDG.rhel10.2.aarch64.rpm
pg_ivm_18 1.14 el10.aarch64 pgdg 49.5 KiB pg_ivm_18-1.14-1PGDG.rhel10.1.aarch64.rpm
pg_ivm_18 1.14 el10.aarch64 pgdg 49.5 KiB pg_ivm_18-1.14-1PGDG.rhel10.0.aarch64.rpm
pg_ivm_18 1.13 el10.aarch64 pgdg 49.7 KiB pg_ivm_18-1.13-1PGDG.rhel10.aarch64.rpm
pg_ivm_18 1.12 el10.aarch64 pgdg 42.8 KiB pg_ivm_18-1.12-1PGDG.rhel10.aarch64.rpm
postgresql-18-pg-ivm 1.15 d12.x86_64 pigsty 124.4 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-ivm 1.13 d12.x86_64 pgdg 118.7 KiB postgresql-18-pg-ivm_1.13-1.pgdg12+1_amd64.deb
postgresql-18-pg-ivm 1.15 d12.aarch64 pigsty 120.8 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-ivm 1.13 d12.aarch64 pgdg 115.4 KiB postgresql-18-pg-ivm_1.13-1.pgdg12+1_arm64.deb
postgresql-18-pg-ivm 1.15 d13.x86_64 pigsty 124.4 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-ivm 1.13 d13.x86_64 pgdg 118.8 KiB postgresql-18-pg-ivm_1.13-1.pgdg13+1_amd64.deb
postgresql-18-pg-ivm 1.15 d13.aarch64 pigsty 120.5 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-ivm 1.13 d13.aarch64 pgdg 114.9 KiB postgresql-18-pg-ivm_1.13-1.pgdg13+1_arm64.deb
postgresql-18-pg-ivm 1.15 u22.x86_64 pigsty 136.1 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-ivm 1.13 u22.x86_64 pgdg 121.6 KiB postgresql-18-pg-ivm_1.13-1.pgdg22.04+1_amd64.deb
postgresql-18-pg-ivm 1.15 u22.aarch64 pigsty 133.8 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-ivm 1.13 u22.aarch64 pgdg 117.9 KiB postgresql-18-pg-ivm_1.13-1.pgdg22.04+1_arm64.deb
postgresql-18-pg-ivm 1.15 u24.x86_64 pigsty 129.8 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~noble_amd64.deb
postgresql-18-pg-ivm 1.13 u24.x86_64 pgdg 118.7 KiB postgresql-18-pg-ivm_1.13-1.pgdg24.04+1_amd64.deb
postgresql-18-pg-ivm 1.15 u24.aarch64 pigsty 128.5 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~noble_arm64.deb
postgresql-18-pg-ivm 1.13 u24.aarch64 pgdg 114.9 KiB postgresql-18-pg-ivm_1.13-1.pgdg24.04+1_arm64.deb
postgresql-18-pg-ivm 1.15 u26.x86_64 pigsty 128.6 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-ivm 1.13 u26.x86_64 pgdg 117.1 KiB postgresql-18-pg-ivm_1.13-1.pgdg26.04+1_amd64.deb
postgresql-18-pg-ivm 1.15 u26.aarch64 pigsty 126.4 KiB postgresql-18-pg-ivm_1.15-1PIGSTY~resolute_arm64.deb
postgresql-18-pg-ivm 1.13 u26.aarch64 pgdg 113.6 KiB postgresql-18-pg-ivm_1.13-1.pgdg26.04+1_arm64.deb

Source

pig build pkg pg_ivm;		# build deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install 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 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_ivm';

Create this extension with:

CREATE EXTENSION pg_ivm;

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:

shared_preload_libraries = 'pg_ivm'

session_preload_libraries = 'pg_ivm' is also supported when managed consistently for all relevant sessions.

CREATE EXTENSION pg_ivm;

SELECT pgivm.create_immv(
    'account_totals',
    'SELECT branch_id, count(*) AS accounts, sum(balance) AS balance
     FROM accounts
     GROUP BY branch_id'
);

UPDATE accounts
SET balance = balance + 100
WHERE account_id = 42;

SELECT * FROM account_totals;

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; false disables 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() and pgivm.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:

pg_ivm_dump_metadata -d application > pg_ivm_metadata.sql

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-in count, sum, avg, min, and max aggregates. Unsupported constructs include HAVING, 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 under REPEATABLE READ or SERIALIZABLE; use READ COMMITTED or 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.
Last updated on