-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- This query gets those tables surpassing the threshold | ||
-- * threshold = vac_base_thresh + vac_scale_factor * reltuples | ||
-- See https://github.com/postgres/postgres/blob/master/src/backend/postmaster/autovacuum.c#L3004 | ||
-- FIXME! This query does not take into account that there could be custom AV options | ||
WITH base AS ( | ||
SELECT schemaname||'.'|| relname as fullrelname, | ||
current_setting('autovacuum_vacuum_threshold')::real + | ||
(current_setting('autovacuum_vacuum_scale_factor')::real* | ||
n_live_tup) as threshold, | ||
n_dead_tup as deadtuples | ||
FROM pg_stat_user_tables | ||
) | ||
SELECT | ||
fullrelname, | ||
pg_size_pretty(pg_total_relation_size(fullrelname::regclass)) AS relationSize, | ||
round(threshold) as threshold, | ||
deadtuples | ||
FROM base | ||
WHERE | ||
deadtuples > threshold | ||
ORDER BY deadtuples DESC | ||
; |