pg_relusage

Log all the queries that reference a particular column

Overview

PackageVersionCategoryLicenseLanguage
pg_relusage0.0.1STATPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
6850pg_relusageNoYesYesNoNoNo-
Relatedpg_freespacemap pg_visibility pgstattuple toastinfo pageinspect pg_buffercache pgfincore old_snapshot

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.0.11817161514pg_relusage-
RPMPIGSTY0.0.11817161514pg_relusage_$v-
DEBPIGSTY0.0.11817161514postgresql-$v-pg-relusage-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
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

Build

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

pig build pkg pg_relusage         # build RPM / DEB packages

Install

You can install pg_relusage 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:

pig install pg_relusage;          # Install for current active PG version
pig ext install -y pg_relusage -v 18  # PG 18
pig ext install -y pg_relusage -v 17  # PG 17
pig ext install -y pg_relusage -v 16  # PG 16
pig ext install -y pg_relusage -v 15  # PG 15
pig ext install -y pg_relusage -v 14  # PG 14
dnf install -y pg_relusage_18       # PG 18
dnf install -y pg_relusage_17       # PG 17
dnf install -y pg_relusage_16       # PG 16
dnf install -y pg_relusage_15       # PG 15
dnf install -y pg_relusage_14       # PG 14
apt install -y postgresql-18-pg-relusage   # PG 18
apt install -y postgresql-17-pg-relusage   # PG 17
apt install -y postgresql-16-pg-relusage   # PG 16
apt install -y postgresql-15-pg-relusage   # PG 15
apt install -y postgresql-14-pg-relusage   # PG 14

Preload:

shared_preload_libraries = 'pg_relusage';

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 Modified 2026-03-12: add pg extension catalog (95749bf)