Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. WITH rel_set AS
  2. (
  3. SELECT
  4. oid,
  5. CASE split_part(split_part(array_to_string(reloptions, ','), 'autovacuum_vacuum_threshold=', 2), ',', 1)
  6. WHEN '' THEN NULL
  7. ELSE split_part(split_part(array_to_string(reloptions, ','), 'autovacuum_vacuum_threshold=', 2), ',', 1)::BIGINT
  8. END AS rel_av_vac_threshold,
  9. CASE split_part(split_part(array_to_string(reloptions, ','), 'autovacuum_vacuum_scale_factor=', 2), ',', 1)
  10. WHEN '' THEN NULL
  11. ELSE split_part(split_part(array_to_string(reloptions, ','), 'autovacuum_vacuum_scale_factor=', 2), ',', 1)::NUMERIC
  12. END AS rel_av_vac_scale_factor
  13. FROM pg_class
  14. )
  15. SELECT
  16. PSUT.relname,
  17. to_char(PSUT.last_vacuum, 'YYYY-MM-DD HH24:MI') AS last_vacuum,
  18. to_char(PSUT.last_autovacuum, 'YYYY-MM-DD HH24:MI') AS last_autovacuum,
  19. to_char(C.reltuples, '9G999G999G999') AS n_tup,
  20. to_char(PSUT.n_dead_tup, '9G999G999G999') AS dead_tup,
  21. to_char(coalesce(RS.rel_av_vac_threshold, current_setting('autovacuum_vacuum_threshold')::BIGINT) + coalesce(RS.rel_av_vac_scale_factor, current_setting('autovacuum_vacuum_scale_factor')::NUMERIC) * C.reltuples, '9G999G999G999') AS av_threshold,
  22. CASE
  23. WHEN (coalesce(RS.rel_av_vac_threshold, current_setting('autovacuum_vacuum_threshold')::BIGINT) + coalesce(RS.rel_av_vac_scale_factor, current_setting('autovacuum_vacuum_scale_factor')::NUMERIC) * C.reltuples) < PSUT.n_dead_tup
  24. THEN '*'
  25. ELSE ''
  26. END AS expect_av
  27. FROM
  28. pg_stat_user_tables PSUT
  29. JOIN pg_class C
  30. ON PSUT.relid = C.oid
  31. JOIN rel_set RS
  32. ON PSUT.relid = RS.oid
  33. ORDER BY C.reltuples DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement