pg_qualstats
pg_qualstats
pg_qualstats : An extension collecting statistics about quals
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 6240 | pg_qualstats
|
pg_qualstats
|
2.1.3 |
STAT
|
BSD 3-Clause
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd--
|
No
|
Yes
|
Yes
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| See Also | hypopg
pg_stat_kcache
powa
pg_stat_statements
index_advisor
pre_prepare
pg_show_plans
pg_stat_monitor
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG
|
2.1.3 |
18
17
16
15
14
|
pg_qualstats |
- |
| RPM | PGDG
|
2.1.2 |
18
17
16
15
14
|
pg_qualstats_$v |
- |
| DEB | PGDG
|
2.1.3 |
18
17
16
15
14
|
postgresql-$v-pg-qualstats |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PGDG 2.1.2
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
el8.aarch64
|
PGDG 2.1.2
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
el9.x86_64
|
PGDG 2.1.2
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
el9.aarch64
|
PGDG 2.1.2
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
el10.x86_64
|
PGDG 2.1.2
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
el10.aarch64
|
PGDG 2.1.2
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
PGDG 2.1.1
|
d12.x86_64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
d12.aarch64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
d13.x86_64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
d13.aarch64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
u22.x86_64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
u22.aarch64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
u24.x86_64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
u24.aarch64
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
PGDG 2.1.3
|
Source
Install
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pg_qualstats; # install via package name, for the active PG version
pig install pg_qualstats -v 18; # install for PG 18
pig install pg_qualstats -v 17; # install for PG 17
pig install pg_qualstats -v 16; # install for PG 16
pig install pg_qualstats -v 15; # install for PG 15
pig install pg_qualstats -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_qualstats';Create this extension with:
CREATE EXTENSION pg_qualstats;Usage
pg_qualstats keeps statistics on predicates found in WHERE clauses and JOIN conditions. It tracks which columns are most frequently queried and which are queried together, enabling index recommendations.
Viewing Predicate Statistics
-- Raw predicate statistics for current database
SELECT * FROM pg_qualstats;
-- Human-readable aggregated form
SELECT * FROM pg_qualstats_pretty;
-- Aggregated per-attribute statistics
SELECT * FROM pg_qualstats_all;
-- Predicates aggregated by query
SELECT * FROM pg_qualstats_by_query;Index Advisor
Generate index suggestions based on collected predicate statistics:
-- Suggest indexes (filtering predicates with >1000 rows and >30% selectivity)
SELECT v FROM json_array_elements(
pg_qualstats_index_advisor(min_filter => 50)->'indexes') v;
-- Show predicates that couldn't be optimized
SELECT v FROM json_array_elements(
pg_qualstats_index_advisor(min_filter => 50)->'unoptimised') v;Utility Functions
-- Get stored query text for a queryid
SELECT pg_qualstats_example_query(queryid);
-- Get all stored query texts
SELECT * FROM pg_qualstats_example_queries();
-- Reset all statistics
SELECT pg_qualstats_reset();Configuration
| Parameter | Default | Description |
|---|---|---|
pg_qualstats.enabled |
true |
Enable/disable collection |
pg_qualstats.track_constants |
true |
Track individual constant values |
pg_qualstats.max |
1000 | Maximum tracked predicates and query texts |
pg_qualstats.resolve_oids |
false |
Resolve OIDs at query time (uses more space) |
pg_qualstats.track_pg_catalog |
false |
Track predicates on pg_catalog objects |
pg_qualstats.sample_rate |
-1 | Fraction of queries to sample (-1 = auto: 1/max_connections) |
Last updated on