Skip to content

pg_relusage

Log the relations actually used by each SQL statement

pg_relusage · Log the relations actually used by each SQL statement

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
6850pg_relusagepg_relusage1.0.2STATPostgreSQLC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sL--rNoYesYesNoyesno
LOAD/preload enables logging; CREATE EXTENSION only records installation.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.0.219 18 17 16 15pg_relusage-
RPMPIGSTY1.0.219 18 17 16 15pg_relusage_$v-
DEBPIGSTY1.0.219 18 17 16 15postgresql-$v-pg-relusage-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
el8.aarch64N/APIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
el9.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
el9.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
el10.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
el10.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
d12.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
d12.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
d13.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
d13.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
u22.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
u22.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
u24.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
u24.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
u26.x86_64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
u26.aarch64PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2PIGSTY 1.0.2
PackageVersionOSORGSIZEFile URL
pg_relusage_191.0.2el9.x86_64pigsty39.8 KiBpg_relusage_19-1.0.2-1PGSTY.el9.x86_64.rpm
pg_relusage_191.0.2el9.aarch64pigsty39.8 KiBpg_relusage_19-1.0.2-1PGSTY.el9.aarch64.rpm
pg_relusage_191.0.2el10.x86_64pigsty40.0 KiBpg_relusage_19-1.0.2-1PGSTY.el10.x86_64.rpm
pg_relusage_191.0.2el10.aarch64pigsty39.9 KiBpg_relusage_19-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-relusage1.0.2d12.x86_64pigsty30.4 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-relusage1.0.2d12.aarch64pigsty29.6 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-relusage1.0.2d13.x86_64pigsty30.4 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-19-pg-relusage1.0.2d13.aarch64pigsty29.8 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-19-pg-relusage1.0.2u22.x86_64pigsty32.4 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-19-pg-relusage1.0.2u22.aarch64pigsty32.3 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-19-pg-relusage1.0.2u24.x86_64pigsty31.7 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~noble_amd64.deb
postgresql-19-pg-relusage1.0.2u24.aarch64pigsty31.1 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~noble_arm64.deb
postgresql-19-pg-relusage1.0.2u26.x86_64pigsty31.4 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-19-pg-relusage1.0.2u26.aarch64pigsty31.2 KiBpostgresql-19-pg-relusage_1.0.2-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_181.0.2el8.x86_64pigsty39.3 KiBpg_relusage_18-1.0.2-1PGSTY.el8.x86_64.rpm
pg_relusage_181.0.2el8.aarch64pigsty39.2 KiBpg_relusage_18-1.0.2-1PGSTY.el8.aarch64.rpm
pg_relusage_181.0.2el9.x86_64pigsty39.8 KiBpg_relusage_18-1.0.2-1PGSTY.el9.x86_64.rpm
pg_relusage_181.0.2el9.aarch64pigsty39.8 KiBpg_relusage_18-1.0.2-1PGSTY.el9.aarch64.rpm
pg_relusage_181.0.2el10.x86_64pigsty40.0 KiBpg_relusage_18-1.0.2-1PGSTY.el10.x86_64.rpm
pg_relusage_181.0.2el10.aarch64pigsty39.9 KiBpg_relusage_18-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-relusage1.0.2d12.x86_64pigsty30.4 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-relusage1.0.2d12.aarch64pigsty29.7 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-relusage1.0.2d13.x86_64pigsty30.4 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-18-pg-relusage1.0.2d13.aarch64pigsty29.8 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-18-pg-relusage1.0.2u22.x86_64pigsty32.4 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-18-pg-relusage1.0.2u22.aarch64pigsty32.3 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-18-pg-relusage1.0.2u24.x86_64pigsty31.7 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~noble_amd64.deb
postgresql-18-pg-relusage1.0.2u24.aarch64pigsty31.1 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~noble_arm64.deb
postgresql-18-pg-relusage1.0.2u26.x86_64pigsty31.4 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-18-pg-relusage1.0.2u26.aarch64pigsty31.2 KiBpostgresql-18-pg-relusage_1.0.2-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_171.0.2el8.x86_64pigsty39.2 KiBpg_relusage_17-1.0.2-1PGSTY.el8.x86_64.rpm
pg_relusage_171.0.2el8.aarch64pigsty39.3 KiBpg_relusage_17-1.0.2-1PGSTY.el8.aarch64.rpm
pg_relusage_171.0.2el9.x86_64pigsty39.8 KiBpg_relusage_17-1.0.2-1PGSTY.el9.x86_64.rpm
pg_relusage_171.0.2el9.aarch64pigsty39.8 KiBpg_relusage_17-1.0.2-1PGSTY.el9.aarch64.rpm
pg_relusage_171.0.2el10.x86_64pigsty40.0 KiBpg_relusage_17-1.0.2-1PGSTY.el10.x86_64.rpm
pg_relusage_171.0.2el10.aarch64pigsty39.9 KiBpg_relusage_17-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-relusage1.0.2d12.x86_64pigsty30.3 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-relusage1.0.2d12.aarch64pigsty29.7 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-relusage1.0.2d13.x86_64pigsty30.2 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-17-pg-relusage1.0.2d13.aarch64pigsty29.8 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-17-pg-relusage1.0.2u22.x86_64pigsty36.2 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-17-pg-relusage1.0.2u22.aarch64pigsty36.2 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-17-pg-relusage1.0.2u24.x86_64pigsty31.4 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~noble_amd64.deb
postgresql-17-pg-relusage1.0.2u24.aarch64pigsty31.1 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~noble_arm64.deb
postgresql-17-pg-relusage1.0.2u26.x86_64pigsty31.2 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-17-pg-relusage1.0.2u26.aarch64pigsty31.1 KiBpostgresql-17-pg-relusage_1.0.2-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_161.0.2el8.x86_64pigsty39.2 KiBpg_relusage_16-1.0.2-1PGSTY.el8.x86_64.rpm
pg_relusage_161.0.2el8.aarch64pigsty39.3 KiBpg_relusage_16-1.0.2-1PGSTY.el8.aarch64.rpm
pg_relusage_161.0.2el9.x86_64pigsty39.8 KiBpg_relusage_16-1.0.2-1PGSTY.el9.x86_64.rpm
pg_relusage_161.0.2el9.aarch64pigsty39.8 KiBpg_relusage_16-1.0.2-1PGSTY.el9.aarch64.rpm
pg_relusage_161.0.2el10.x86_64pigsty40.0 KiBpg_relusage_16-1.0.2-1PGSTY.el10.x86_64.rpm
pg_relusage_161.0.2el10.aarch64pigsty39.9 KiBpg_relusage_16-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-relusage1.0.2d12.x86_64pigsty30.3 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-relusage1.0.2d12.aarch64pigsty29.7 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-relusage1.0.2d13.x86_64pigsty30.2 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-16-pg-relusage1.0.2d13.aarch64pigsty29.8 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-16-pg-relusage1.0.2u22.x86_64pigsty35.8 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-16-pg-relusage1.0.2u22.aarch64pigsty35.8 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-16-pg-relusage1.0.2u24.x86_64pigsty31.5 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~noble_amd64.deb
postgresql-16-pg-relusage1.0.2u24.aarch64pigsty31.0 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~noble_arm64.deb
postgresql-16-pg-relusage1.0.2u26.x86_64pigsty31.3 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-16-pg-relusage1.0.2u26.aarch64pigsty31.1 KiBpostgresql-16-pg-relusage_1.0.2-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_151.0.2el8.x86_64pigsty39.2 KiBpg_relusage_15-1.0.2-1PGSTY.el8.x86_64.rpm
pg_relusage_151.0.2el8.aarch64pigsty39.2 KiBpg_relusage_15-1.0.2-1PGSTY.el8.aarch64.rpm
pg_relusage_151.0.2el9.x86_64pigsty39.7 KiBpg_relusage_15-1.0.2-1PGSTY.el9.x86_64.rpm
pg_relusage_151.0.2el9.aarch64pigsty39.8 KiBpg_relusage_15-1.0.2-1PGSTY.el9.aarch64.rpm
pg_relusage_151.0.2el10.x86_64pigsty40.0 KiBpg_relusage_15-1.0.2-1PGSTY.el10.x86_64.rpm
pg_relusage_151.0.2el10.aarch64pigsty39.9 KiBpg_relusage_15-1.0.2-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-relusage1.0.2d12.x86_64pigsty30.3 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-relusage1.0.2d12.aarch64pigsty29.7 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-relusage1.0.2d13.x86_64pigsty30.2 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~trixie_amd64.deb
postgresql-15-pg-relusage1.0.2d13.aarch64pigsty29.8 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~trixie_arm64.deb
postgresql-15-pg-relusage1.0.2u22.x86_64pigsty35.7 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~jammy_amd64.deb
postgresql-15-pg-relusage1.0.2u22.aarch64pigsty35.7 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~jammy_arm64.deb
postgresql-15-pg-relusage1.0.2u24.x86_64pigsty31.5 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~noble_amd64.deb
postgresql-15-pg-relusage1.0.2u24.aarch64pigsty31.0 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~noble_arm64.deb
postgresql-15-pg-relusage1.0.2u26.x86_64pigsty31.2 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~resolute_amd64.deb
postgresql-15-pg-relusage1.0.2u26.aarch64pigsty31.2 KiBpostgresql-15-pg-relusage_1.0.2-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_relusage;		# build rpm/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_relusage;		# install by package name

pig install pg_relusage -v 19;   # install for PG 19
pig install pg_relusage -v 18;   # install for PG 18
pig install pg_relusage -v 17;   # install for PG 17
pig install pg_relusage -v 16;   # install for PG 16
pig install pg_relusage -v 15;   # install for PG 15

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_relusage';

This extension does not need CREATE EXTENSION DDL command

Usage

Sources:

pg_relusage 1.0.2 logs relations used by statements after plan simplification. It supports PostgreSQL 10–18 and defines no SQL objects. Loading the library enables it; optional CREATE EXTENSION only records installation.

Core Workflow

LOAD 'pg_relusage';
SET pg_relusage.nested_statements = 'fold';
SET pg_relusage.log_level = 'notice';
CREATE TABLE relusage_demo (id integer);
SELECT * FROM relusage_demo;

Operational Boundaries

All settings require superuser: pg_relusage.enabled defaults on, pg_relusage.log_level defaults log and pg_relusage.rel_kinds defaults riSvmfp. pg_relusage.nested_statements accepts all (default: each statement), top (ignore nested statements) or fold (merge nested relations into the outer log). Version 1.0.1 fixes fold handling after a failed subtransaction.

Use session_preload_libraries for new sessions without a restart, or shared_preload_libraries for all sessions with a restart; preserve existing preload entries. LOAD normally requires superuser. Log messages omit SQL text, so configure log_line_prefix to identify the client.

System catalogs are excluded. Relations eliminated by planning or startup pruning are excluded, but partitions skipped later during execution can still appear. INSERT into a partitioned table reports only its parent. Deferred triggers at COMMIT, COPY FROM triggers and planner-invoked functions are treated as top-level statements. DDL and maintenance commands are excluded. A quiet log alone does not prove an object can be dropped.

1.0.2 and Partitioned Tables

Version 1.0.2 reduces relation-membership and partition-matching overhead for statements involving many partitions. Log format and settings are unchanged. Replace the library and restart if using shared preload, or reconnect when using session preload or LOAD. If installation was recorded with CREATE EXTENSION, also run ALTER EXTENSION pg_relusage UPDATE.

Table reader