pg_relusage

pg_relusage

pg_relusage : Log all the queries that reference a particular column

Overview

ID Extension Package Version Category License Language
6850
pg_relusage
pg_relusage
0.0.1
STAT
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sL---
No
Yes
Yes
No
no
no
Relationships
See Also
pg_freespacemap
pg_visibility
pgstattuple
toastinfo
pageinspect
pg_buffercache
pgfincore
old_snapshot

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
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 / PG PG18 PG17 PG16 PG15 PG14
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
Package Version OS ORG SIZE File URL
pg_relusage_18 0.0.1 el8.x86_64 pigsty 13.1 KiB pg_relusage_18-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_18 0.0.1 el8.aarch64 pigsty 13.5 KiB pg_relusage_18-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_18 0.0.1 el9.x86_64 pigsty 13.0 KiB pg_relusage_18-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_18 0.0.1 el9.aarch64 pigsty 13.2 KiB pg_relusage_18-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_18 0.0.1 el10.x86_64 pigsty 13.0 KiB pg_relusage_18-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_18 0.0.1 el10.aarch64 pigsty 13.4 KiB pg_relusage_18-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-relusage 0.0.1 d12.x86_64 pigsty 12.1 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-relusage 0.0.1 d12.aarch64 pigsty 12.1 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-relusage 0.0.1 d13.x86_64 pigsty 12.1 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-relusage 0.0.1 d13.aarch64 pigsty 12.1 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-relusage 0.0.1 u22.x86_64 pigsty 12.4 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-relusage 0.0.1 u22.aarch64 pigsty 12.4 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-relusage 0.0.1 u24.x86_64 pigsty 12.6 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-18-pg-relusage 0.0.1 u24.aarch64 pigsty 12.5 KiB postgresql-18-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_relusage_17 0.0.1 el8.x86_64 pigsty 13.1 KiB pg_relusage_17-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_17 0.0.1 el8.aarch64 pigsty 13.5 KiB pg_relusage_17-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_17 0.0.1 el9.x86_64 pigsty 13.1 KiB pg_relusage_17-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_17 0.0.1 el9.aarch64 pigsty 13.3 KiB pg_relusage_17-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_17 0.0.1 el10.x86_64 pigsty 13.1 KiB pg_relusage_17-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_17 0.0.1 el10.aarch64 pigsty 13.4 KiB pg_relusage_17-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-relusage 0.0.1 d12.x86_64 pigsty 12.0 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-relusage 0.0.1 d12.aarch64 pigsty 12.1 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-relusage 0.0.1 d13.x86_64 pigsty 12.0 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-relusage 0.0.1 d13.aarch64 pigsty 12.1 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-relusage 0.0.1 u22.x86_64 pigsty 14.6 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-relusage 0.0.1 u22.aarch64 pigsty 14.6 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-relusage 0.0.1 u24.x86_64 pigsty 12.6 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-17-pg-relusage 0.0.1 u24.aarch64 pigsty 12.6 KiB postgresql-17-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_relusage_16 0.0.1 el8.x86_64 pigsty 13.1 KiB pg_relusage_16-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_16 0.0.1 el8.aarch64 pigsty 13.5 KiB pg_relusage_16-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_16 0.0.1 el9.x86_64 pigsty 13.1 KiB pg_relusage_16-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_16 0.0.1 el9.aarch64 pigsty 13.3 KiB pg_relusage_16-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_16 0.0.1 el10.x86_64 pigsty 13.1 KiB pg_relusage_16-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_16 0.0.1 el10.aarch64 pigsty 13.4 KiB pg_relusage_16-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-relusage 0.0.1 d12.x86_64 pigsty 12.1 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-relusage 0.0.1 d12.aarch64 pigsty 12.1 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-relusage 0.0.1 d13.x86_64 pigsty 12.0 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-relusage 0.0.1 d13.aarch64 pigsty 12.1 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-relusage 0.0.1 u22.x86_64 pigsty 14.5 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-relusage 0.0.1 u22.aarch64 pigsty 14.6 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-relusage 0.0.1 u24.x86_64 pigsty 12.6 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-16-pg-relusage 0.0.1 u24.aarch64 pigsty 12.5 KiB postgresql-16-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_relusage_15 0.0.1 el8.x86_64 pigsty 13.1 KiB pg_relusage_15-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_15 0.0.1 el8.aarch64 pigsty 13.5 KiB pg_relusage_15-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_15 0.0.1 el9.x86_64 pigsty 13.1 KiB pg_relusage_15-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_15 0.0.1 el9.aarch64 pigsty 13.3 KiB pg_relusage_15-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_15 0.0.1 el10.x86_64 pigsty 13.1 KiB pg_relusage_15-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_15 0.0.1 el10.aarch64 pigsty 13.4 KiB pg_relusage_15-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-relusage 0.0.1 d12.x86_64 pigsty 12.1 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-relusage 0.0.1 d12.aarch64 pigsty 12.1 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-relusage 0.0.1 d13.x86_64 pigsty 12.0 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-relusage 0.0.1 d13.aarch64 pigsty 12.2 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-relusage 0.0.1 u22.x86_64 pigsty 14.5 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-relusage 0.0.1 u22.aarch64 pigsty 14.6 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-relusage 0.0.1 u24.x86_64 pigsty 12.6 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-15-pg-relusage 0.0.1 u24.aarch64 pigsty 12.6 KiB postgresql-15-pg-relusage_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_relusage_14 0.0.1 el8.x86_64 pigsty 13.1 KiB pg_relusage_14-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_relusage_14 0.0.1 el8.aarch64 pigsty 13.5 KiB pg_relusage_14-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_relusage_14 0.0.1 el9.x86_64 pigsty 13.1 KiB pg_relusage_14-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_relusage_14 0.0.1 el9.aarch64 pigsty 13.3 KiB pg_relusage_14-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_relusage_14 0.0.1 el10.x86_64 pigsty 13.1 KiB pg_relusage_14-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_relusage_14 0.0.1 el10.aarch64 pigsty 13.4 KiB pg_relusage_14-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-relusage 0.0.1 d12.x86_64 pigsty 12.0 KiB postgresql-14-pg-relusage_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-relusage 0.0.1 d12.aarch64 pigsty 12.1 KiB postgresql-14-pg-relusage_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-relusage 0.0.1 d13.x86_64 pigsty 12.0 KiB postgresql-14-pg-relusage_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-relusage 0.0.1 d13.aarch64 pigsty 12.1 KiB postgresql-14-pg-relusage_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-relusage 0.0.1 u22.x86_64 pigsty 14.5 KiB postgresql-14-pg-relusage_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-relusage 0.0.1 u22.aarch64 pigsty 14.6 KiB postgresql-14-pg-relusage_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-relusage 0.0.1 u24.x86_64 pigsty 12.6 KiB postgresql-14-pg-relusage_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-14-pg-relusage 0.0.1 u24.aarch64 pigsty 12.5 KiB postgresql-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

Parameter Default Description
pg_relusage.log_level LOG Log 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