pg_relusage

pg_relusage

pg_relusage : Log all the queries that reference a particular column

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
6850
pg_relusage
pg_relusage
0.0.1
STAT
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sL---
No
Yes
Yes
No
no
no
Relationships
See Also
pg_freespacemap
pg_visibility
pgstattuple
toastinfo
pageinspect
pg_buffercache
pgfincore
old_snapshot

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.0.1
18
17
16
15
14
pg_relusage-
RPM
PIGSTY
0.0.1
18
17
16
15
14
pg_relusage_$v-
DEB
PIGSTY
0.0.1
18
17
16
15
14
postgresql-$v-pg-relusage-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el8.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el9.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el9.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el10.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el10.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d12.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d12.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PackageVersionOSORGSIZEFile URL
pg_relusage_180.0.1el8.x86_64pigsty13.1 KiBpg_relusage_18-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_180.0.1el8.aarch64pigsty13.5 KiBpg_relusage_18-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_180.0.1el9.x86_64pigsty13.0 KiBpg_relusage_18-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_180.0.1el9.aarch64pigsty13.2 KiBpg_relusage_18-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_180.0.1el10.x86_64pigsty13.0 KiBpg_relusage_18-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_180.0.1el10.aarch64pigsty13.4 KiBpg_relusage_18-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-relusage0.0.1d12.x86_64pigsty12.1 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-relusage0.0.1d12.aarch64pigsty12.1 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-relusage0.0.1d13.x86_64pigsty12.1 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-relusage0.0.1d13.aarch64pigsty12.1 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-relusage0.0.1u22.x86_64pigsty12.4 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-relusage0.0.1u22.aarch64pigsty12.4 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-relusage0.0.1u24.x86_64pigsty12.6 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-18-pg-relusage0.0.1u24.aarch64pigsty12.5 KiBpostgresql-18-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_170.0.1el8.x86_64pigsty13.1 KiBpg_relusage_17-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_170.0.1el8.aarch64pigsty13.5 KiBpg_relusage_17-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_170.0.1el9.x86_64pigsty13.1 KiBpg_relusage_17-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_170.0.1el9.aarch64pigsty13.3 KiBpg_relusage_17-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_170.0.1el10.x86_64pigsty13.1 KiBpg_relusage_17-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_170.0.1el10.aarch64pigsty13.4 KiBpg_relusage_17-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-relusage0.0.1d12.x86_64pigsty12.0 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-relusage0.0.1d12.aarch64pigsty12.1 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-relusage0.0.1d13.x86_64pigsty12.0 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-relusage0.0.1d13.aarch64pigsty12.1 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-relusage0.0.1u22.x86_64pigsty14.6 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-relusage0.0.1u22.aarch64pigsty14.6 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-relusage0.0.1u24.x86_64pigsty12.6 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-17-pg-relusage0.0.1u24.aarch64pigsty12.6 KiBpostgresql-17-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_160.0.1el8.x86_64pigsty13.1 KiBpg_relusage_16-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_160.0.1el8.aarch64pigsty13.5 KiBpg_relusage_16-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_160.0.1el9.x86_64pigsty13.1 KiBpg_relusage_16-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_160.0.1el9.aarch64pigsty13.3 KiBpg_relusage_16-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_160.0.1el10.x86_64pigsty13.1 KiBpg_relusage_16-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_160.0.1el10.aarch64pigsty13.4 KiBpg_relusage_16-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-relusage0.0.1d12.x86_64pigsty12.1 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-relusage0.0.1d12.aarch64pigsty12.1 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-relusage0.0.1d13.x86_64pigsty12.0 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-relusage0.0.1d13.aarch64pigsty12.1 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-relusage0.0.1u22.x86_64pigsty14.5 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-relusage0.0.1u22.aarch64pigsty14.6 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-relusage0.0.1u24.x86_64pigsty12.6 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-16-pg-relusage0.0.1u24.aarch64pigsty12.5 KiBpostgresql-16-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_150.0.1el8.x86_64pigsty13.1 KiBpg_relusage_15-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_150.0.1el8.aarch64pigsty13.5 KiBpg_relusage_15-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_150.0.1el9.x86_64pigsty13.1 KiBpg_relusage_15-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_150.0.1el9.aarch64pigsty13.3 KiBpg_relusage_15-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_150.0.1el10.x86_64pigsty13.1 KiBpg_relusage_15-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_150.0.1el10.aarch64pigsty13.4 KiBpg_relusage_15-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-relusage0.0.1d12.x86_64pigsty12.1 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-relusage0.0.1d12.aarch64pigsty12.1 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-relusage0.0.1d13.x86_64pigsty12.0 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-relusage0.0.1d13.aarch64pigsty12.2 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-relusage0.0.1u22.x86_64pigsty14.5 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-relusage0.0.1u22.aarch64pigsty14.6 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-relusage0.0.1u24.x86_64pigsty12.6 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-15-pg-relusage0.0.1u24.aarch64pigsty12.6 KiBpostgresql-15-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_relusage_140.0.1el8.x86_64pigsty13.1 KiBpg_relusage_14-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_140.0.1el8.aarch64pigsty13.5 KiBpg_relusage_14-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_140.0.1el9.x86_64pigsty13.1 KiBpg_relusage_14-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_140.0.1el9.aarch64pigsty13.3 KiBpg_relusage_14-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_140.0.1el10.x86_64pigsty13.1 KiBpg_relusage_14-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_140.0.1el10.aarch64pigsty13.4 KiBpg_relusage_14-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-relusage0.0.1d12.x86_64pigsty12.0 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-relusage0.0.1d12.aarch64pigsty12.1 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-relusage0.0.1d13.x86_64pigsty12.0 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-relusage0.0.1d13.aarch64pigsty12.1 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-relusage0.0.1u22.x86_64pigsty14.5 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-relusage0.0.1u22.aarch64pigsty14.6 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-relusage0.0.1u24.x86_64pigsty12.6 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-14-pg-relusage0.0.1u24.aarch64pigsty12.5 KiBpostgresql-14-pg-relusage_0.0.1-1PIGSTY~noble_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 via package name, for the active PG version

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
pig install pg_relusage -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_relusage';

This extension does not need CREATE EXTENSION DDL command

Usage

pg_relusage: log relations actually used by SQL statements

pg_relusage hooks into the query executor and logs which relations (tables, views, indexes, etc.) are actually used by each SQL statement. Unlike the statement log, it reports relations after view expansion and unused join elimination.

How It Works

Once loaded, each SQL statement emits a log message listing all referenced relations:

SELECT * FROM pg_stats LIMIT 1;

Produces log output:

relations used: pg_stats,pg_statistic,pg_class,pg_attribute,pg_namespace

Loading

-- Per-session
LOAD 'pg_relusage';

-- Or globally in postgresql.conf
shared_preload_libraries = 'pg_relusage'

Configuration

ParameterDefaultDescription
pg_relusage.log_levelLOGLog level for relation messages
pg_relusage.rel_kinds'riSvmfp'Relation kinds to report (one-letter codes from pg_class.relkind)

Relation kind codes: r = table, i = index, S = sequence, v = view, m = materialized view, f = foreign table, p = partitioned table.

Use Case

This extension is useful for discovering unused objects in legacy databases. By analyzing the logged relation usage over time, you can identify which tables, views, and indexes are actually accessed by your application.

Last updated on