Module: PgHero::Methods::Space
- Included in:
- Database
- Defined in:
- lib/pghero/methods/space.rb
Instance Method Summary collapse
Instance Method Details
#capture_space_stats ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/pghero/methods/space.rb', line 30 def capture_space_stats now = Time.now columns = %w[database schema relation size captured_at] values = [] relation_sizes.each do |rs| values << [id, rs["schema"], rs["name"], rs["size_bytes"].to_i, now] end insert_stats("pghero_space_stats", columns, values) end |
#database_size ⇒ Object
4 5 6 |
# File 'lib/pghero/methods/space.rb', line 4 def database_size select_all("SELECT pg_size_pretty(pg_database_size(current_database()))").first["pg_size_pretty"] end |
#relation_sizes ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pghero/methods/space.rb', line 8 def relation_sizes select_all " SELECT\n n.nspname AS schema,\n c.relname AS name,\n CASE WHEN c.relkind = 'r' THEN 'table' ELSE 'index' END AS type,\n pg_size_pretty(pg_table_size(c.oid)) AS size,\n pg_table_size(c.oid) AS size_bytes\n FROM\n pg_class c\n LEFT JOIN\n pg_namespace n ON (n.oid = c.relnamespace)\n WHERE\n n.nspname NOT IN ('pg_catalog', 'information_schema')\n AND n.nspname !~ '^pg_toast'\n AND c.relkind IN ('r', 'i')\n ORDER BY\n pg_table_size(c.oid) DESC,\n name ASC\n SQL\nend\n" |