Class: Webhookdb::Postgres::Maintenance::Tables

Inherits:
Query
  • Object
show all
Defined in:
lib/webhookdb/postgres/maintenance.rb

Instance Attribute Summary

Attributes inherited from Base

#service_integration

Instance Method Summary collapse

Methods inherited from Query

#connstr, #fetch

Methods inherited from Base

#conn_params, #debug?, #initialize

Constructor Details

This class inherits a constructor from Webhookdb::Postgres::Maintenance::Base

Instance Method Details

#queryObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/webhookdb/postgres/maintenance.rb', line 138

def query
  return <<~SQL
    SELECT
        relname AS "relation",
        reltuples as "tuples",
        pg_size_pretty(pg_total_relation_size(C .oid)) as "size"
    FROM pg_class C
    LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
    WHERE nspname NOT IN ('pg_catalog', 'information_schema')
    AND C.relkind = 'r'
    AND nspname !~ '^pg_toast'
    ORDER BY C.relname
  SQL
end

#runObject



153
154
155
# File 'lib/webhookdb/postgres/maintenance.rb', line 153

def run
  return self.fetch
end

#run_fmtObject



157
158
159
160
161
162
163
164
# File 'lib/webhookdb/postgres/maintenance.rb', line 157

def run_fmt
  rows = self.run
  namejust = rows.map { |r| r[:relation].size }.max
  return rows.map do |r|
    tuples = ActiveSupport::NumberHelper.number_to_delimited(r[:tuples].to_i).rjust(12, " ")
    "#{r[:relation].ljust(namejust + 1, ' ')} #{r[:size].ljust(7, ' ')} #{tuples}"
  end.join("\n")
end