pg_relusage
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_relusage | 0.0.1 | STAT | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 6850 | pg_relusage | No | Yes | Yes | No | No | No | - |
| Related | pg_freespacemap pg_visibility pgstattuple toastinfo pageinspect pg_buffercache pgfincore old_snapshot |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.1 | 1817161514 | pg_relusage | - |
| RPM | PIGSTY | 0.0.1 | 1817161514 | pg_relusage_$v | - |
| DEB | PIGSTY | 0.0.1 | 1817161514 | postgresql-$v-pg-relusage | - |
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 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.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.