Skip to content

pg_lion

Roaring bitmap inverted indexes for filtering, counts and aggregates

Overview

PackageVersionCategoryLicenseLanguage
pg_lion0.3.0FEATPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
2715pg_lionNoYesNoYesNoYes-
2716pg_lion_citextNoNoNoYesNoYes-
2717pg_lion_vectorNoYesNoYesNoYes-
Related
Depended Bypg_lion_citext pg_lion_vector

Custom WAL requires preload.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.3.01817161514pg_lion-
RPMPIGSTY0.3.01817161514pg_lion_$v-
DEBPIGSTY0.3.01817161514postgresql-$v-pg-lion-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64N/AN/A
el8.aarch64N/AN/A
el9.x86_64N/AN/A
el9.aarch64N/AN/A
el10.x86_64N/AN/A
el10.aarch64N/AN/A
d12.x86_64N/AN/A
d12.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A
d13.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A
d13.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A
u22.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A
u22.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A
u24.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A
u24.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A
u26.x86_64N/AN/A
u26.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
N/AN/A

Build

You can build the RPM / DEB packages for pg_lion using pig build:

pig build pkg pg_lion         # build RPM / DEB packages

Install

You can install pg_lion directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

Install
pig install pg_lion;          # Install for current active PG version
pig
pig ext install -y pg_lion -v 18  # PG 18
pig ext install -y pg_lion -v 17  # PG 17
pig ext install -y pg_lion -v 16  # PG 16
dnf
dnf install -y pg_lion_18       # PG 18
dnf install -y pg_lion_17       # PG 17
dnf install -y pg_lion_16       # PG 16
apt
apt install -y postgresql-18-pg-lion   # PG 18
apt install -y postgresql-17-pg-lion   # PG 17
apt install -y postgresql-16-pg-lion   # PG 16

Create Extension:

CREATE EXTENSION pg_lion;

Usage

Sources:

pg_lion 0.3.0 adds roaring bitmap inverted indexes for filtering, counts and grouped aggregates on PostgreSQL 16 and later. It works on heap tables and uses ordinary PostgreSQL operators; it does not require preloading for its default generic WAL mode.

Core Workflow

Create lion indexes on the columns used by filters and groups. Vacuumed, all-visible pages let counts avoid heap visits; recently changed pages may need visibility checks in the heap.

CREATE EXTENSION pg_lion;
CREATE TABLE lion_events (country text, amount integer);
INSERT INTO lion_events VALUES ('JP', 10), ('JP', 20), ('NZ', 30);
CREATE INDEX lion_country ON lion_events USING lion (country);
CREATE INDEX lion_amount ON lion_events USING lion (amount) WITH (slices = on);
VACUUM ANALYZE lion_events;
SELECT count(*), sum(amount) FROM lion_events WHERE country = 'JP';
SELECT country, count(*) FROM lion_events GROUP BY country;

Scalar equality, ranges, IN, null tests and combined predicates are supported. lion also indexes arrays, jsonb and tsvector; lion_bm25_score ranks full-text matches. An expression index on a JSON field can support grouping that a default jsonb index cannot.

Options and Diagnostics

ObjectPurpose
summaries = autoPre-merge bitmaps to accelerate ranges with many distinct values.
slices = onStore bit slices for filtered aggregates on integer, date and time values; adds write and storage cost.
lion_index_count(index, key)Count a key through a named index.
lion_index_stats(index)Inspect index statistics; initially granted to pg_stat_scan_tables.
lion_index_verify(index, true)Check structure and heap coverage; restricted diagnostic function.
lion_index_wal_mode(index)Report generic or rmgr; restricted diagnostic function.

pg_lion_citext adds the citext operator class. pg_lion_vector adds the lionvec access method and requires pgvector 0.7 or later. Both companions ship with the parent distribution and are enabled separately.

WAL and Operational Boundaries

Creating the extensions requires a superuser. Optional shared_preload_libraries = 'pg_lion' plus a server restart enables the custom WAL resource manager (default ID 170). Indexes built in that mode require the preload for writes and VACUUM until rebuilt; check lion_index_wal_mode before changing the setting.

Keep the library preloaded wherever old custom WAL may still be replayed, including standbys and archive recovery. REINDEX does not rewrite historical WAL. Before removing the preload, rebuild every rmgr index with wal_mode = generic while the library is still preloaded, and account for WAL replay consumers.

There are no unique indexes or INCLUDE columns, and only heap tables are supported. Keep B-tree indexes for uniqueness and ordinary ordered scans. Loading the library installs planner hooks and can affect estimates for other queries. Measure write-heavy workloads before adding indexes or slices.

The on-disk format may change before 1.0; follow release-specific REINDEX requirements. Builds predating 0.3.0 have no extension update path: upstream requires recreating the extensions and their indexes. Version 0.3.0 supplies installation scripts only.

Was this page helpful?

Table reader