0

マルチテナント アプリ レールがあり、アカウントごとにスキーマ 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

誰が間違いを教えてもらえますか?

  • スキーマのディスク サイズを取得し、データベースに格納します

助けて。

ありがとう

4

1 に答える 1