Skip to content

Commit

Permalink
GUCs explained
Browse files Browse the repository at this point in the history
  • Loading branch information
adept authored Oct 26, 2022
1 parent e7e3779 commit ee2912d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ pg_relusage is a PostgreSQL extension which allows one to discover and log the r

## Why?

This extension will be useful if you are dealing with (large?) legacy database and suspect that it contains plenty of unused objects.
This extension will be useful if you are dealing with (large?) legacy database and suspect that (you suspect) contains plenty of unused objects.

This extension will allow you to quickly get an understanding of which clients use which objects / relations. Unlike statement log, which will only show you the views and tables explicitly referenced in the query, this extension will essentially expant all the view definitions etc and give you the list of all relations used by the statement, even indirectly.
This extension will allow you to quickly get an understanding of which clients use which objects / relations. Unlike statement log, which will only show you the views and tables explicitly referenced by the query, this extension will cut look at the result of view expansion, unused joins elimination etc etc and report the relations that were *actually* used by the statement.

## Installation

Extension hooks into PostgreSQL query executor and therefore needs to be compiled using PostgreSQL headers for the appropriate server version,
and then loaded into server proces via [load](https://www.postgresql.org/docs/current/sql-load.html) statement or [shared_preload_libraries](https://postgresqlco.nf/doc/en/param/shared_preload_libraries/) configuration parameter.
and then loaded into server process.

Extension uses standard PGXS build infrastructure and (provided that `pg_config` is somewhere in your PATH) could be built with `make install`.

## Usage

After installation, extension has to be either loaded into a single client process via [load](https://www.postgresql.org/docs/current/sql-load.html) statement or enabled for all sessions globally via [shared_preload_libraries](https://postgresqlco.nf/doc/en/param/shared_preload_libraries/) configuration parameter.

Once extension is loaded, each SQL statement will emit one extra log message which will list all the referenced relations (by name).

Statement:
Expand All @@ -31,6 +33,13 @@ should produce log message along the lines of:
relations used: pg_stats,pg_statistic,pg_class,pg_attribute,pg_namespace
```

## Configuration

Extension provides two user settings:

* pg_relusage.log_level (defaults to `LOG`), with the obvious meaning and the same set of values that similar configuration items (like `client_min_messages` support)
* pg_relusage.rel_kinds (defaults to `'riSvmfp'`) which specifies which relation kinds will be reported. This is a list of one-letter codes used in the `relkind` field in the `pg_class` (full list could be seen [here](https://www.postgresql.org/docs/current/catalog-pg-class.html)).

## Limitations

Not tested on PostgreSQL below v10 (though it should work).
Expand Down

0 comments on commit ee2912d

Please sign in to comment.