我有多租户应用程序轨道,并试图为每个帐户获取模式 posgresql 的大小磁盘。最初,我在视图中进行了尝试,大致如下:
<% for account in @accounts %>
<td>
<%= number_to_human_size(@schemasize = (ActiveRecord::Base.connection.select_rows(%q{select sum(pg_total_relation_size(table_schema || '.' || table_name)) from information_schema.tables where table_schema in ('} +account.schema+ %q{') group by table_schema}).to_s.gsub(/\D/, '').to_f + account.size_logo.to_f), :locale=> 'en') %>
</td>
<% end %>
浏览器输出
| schema | usage |
|_________|________|
| schema1 | 259 KB |
| schema2 | 294 KB |
但它没有插入数据库(在公共模式上)。现在,我希望它存储在数据库中。
这是每个帐户的模式处理大小磁盘的控制器:
@accounts.each do |t|
select_size = "select sum(pg_total_relation_size(table_schema || '.' || table_name)) from information_schema.tables where table_schema = " + t.schema.to_s + " group by table_schema"
@a = ActiveRecord::Base.connection.select_rows(select_size)
@b = @a.to_s.gsub(/\D/, '').to_f
@c = t.size_logo.to_f
@d = @b + @c
@cek_schema = Usage.find_by_account_id(t.id)
if @cek_schema.nil?
Usage.create(:account_id => t.id, :size => @d)
else
@cek_schema.destroy
Usage.create(:account_id => t.id, :size => @d)
end
end
我收到一个错误
ActiveRecord::StatementInvalid in AccountsController#kapasitas
PG::Error: ERROR: column "schema1" does not exist
LINE 1: ... from information_schema.tables where table_schema = schema1
^
: select sum(pg_total_relation_size(table_schema || '.' || table_name)) from information_schema.tables where table_schema = schema1 group by table_schema
谁能告诉我是什么错误?
- 获取模式的大小磁盘并存储在数据库中
帮我。
谢谢