-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from cybertec-postgresql/invalid_indexes_metric
[+] add new metrics for invalid and unused indexes
- Loading branch information
Showing
11 changed files
with
260 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
select /* pgwatch3_generated */ | ||
(extract(epoch from now()) * 1e9)::int8 as epoch_ns, | ||
format('%I.%I', n.nspname , ci.relname) as tag_index_full_name, | ||
coalesce(pg_relation_size(indexrelid), 0) as index_size_b | ||
from | ||
pg_index i | ||
join pg_class ci on ci.oid = i.indexrelid | ||
join pg_class cr on cr.oid = i.indrelid | ||
join pg_namespace n on n.oid = ci.relnamespace | ||
where not n.nspname like E'pg\\_temp%' | ||
and not indisvalid | ||
and not exists ( /* leave out ones that are being actively rebuilt */ | ||
select * from pg_locks l | ||
join pg_stat_activity a using (pid) | ||
where l.relation = i.indexrelid | ||
and a.state = 'active' | ||
and a.query ~* 'concurrently' | ||
) | ||
and not exists (select * from pg_locks where relation = indexrelid and mode = 'AccessExclusiveLock') /* can't get size then */ | ||
order by index_size_b desc | ||
limit 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
select /* pgwatch3_generated */ | ||
(extract(epoch from now()) * 1e9)::int8 as epoch_ns, | ||
* | ||
from ( | ||
select | ||
format('%I.%I', sui.schemaname, sui.indexrelname) as tag_index_full_name, | ||
sui.idx_scan, | ||
coalesce(pg_relation_size(sui.indexrelid), 0) as index_size_b, | ||
system_identifier::text as tag_sys_id /* to easily check also all replicas as could be still used there */ | ||
from | ||
pg_stat_user_indexes sui | ||
join pg_index i on i.indexrelid = sui.indexrelid | ||
join pg_control_system() on true | ||
where not sui.schemaname like E'pg\\_temp%' | ||
and idx_scan = 0 | ||
and not (indisprimary or indisunique or indisexclusion) | ||
and not exists (select * from pg_locks where relation = sui.relid and mode = 'AccessExclusiveLock') | ||
) x | ||
where index_size_b > 100*1024^2 /* list >100MB only */ | ||
order by index_size_b desc | ||
limit 25; |