Sha256: 8d4ac23f77ae61a2e3a72d2dbd3b82cfd4242341f8086c62159ac7c4c61de331

Contents?: true

Size: 850 Bytes

Versions: 8

Compression:

Stored size: 850 Bytes

Contents

module PgHero
  module Methods
    module Space
      def database_size
        select_all("SELECT pg_size_pretty(pg_database_size(current_database()))").first["pg_size_pretty"]
      end

      def relation_sizes
        select_all <<-SQL
          SELECT
            n.nspname AS schema,
            c.relname AS name,
            CASE WHEN c.relkind = 'r' THEN 'table' ELSE 'index' END AS type,
            pg_size_pretty(pg_table_size(c.oid)) AS size
          FROM
            pg_class c
          LEFT JOIN
            pg_namespace n ON (n.oid = c.relnamespace)
          WHERE
            n.nspname NOT IN ('pg_catalog', 'information_schema')
            AND n.nspname !~ '^pg_toast'
            AND c.relkind IN ('r', 'i')
          ORDER BY
            pg_table_size(c.oid) DESC,
            name ASC
        SQL
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pghero-1.4.2 lib/pghero/methods/space.rb
pghero-1.4.1 lib/pghero/methods/space.rb
pghero-1.4.0 lib/pghero/methods/space.rb
pghero-1.3.2 lib/pghero/methods/space.rb
pghero-1.3.1 lib/pghero/methods/space.rb
pghero-1.3.0 lib/pghero/methods/space.rb
pghero-1.2.4 lib/pghero/methods/space.rb
pghero-1.2.3 lib/pghero/methods/space.rb