postgre_sql.rb 905 B

123456789101112131415161718
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class SystemReport::Plugin::PostgreSql < SystemReport::Plugin
  3. DESCRIPTION = __('PostgresSQL server version').freeze
  4. def fetch
  5. return if ActiveRecord::Base.connection.adapter_name != 'PostgreSQL'
  6. database_name = Rails.configuration.database_configuration[Rails.env]['database']
  7. ActiveRecord::Base.connection.execute("
  8. SELECT version() as version,
  9. pg_database_size('#{ActiveRecord::Base.connection.quote_string(database_name)}') as database_size,
  10. pg_size_pretty(pg_database_size('#{ActiveRecord::Base.connection.quote_string(database_name)}')) as database_size_human,
  11. (SELECT SUM(CAST(coalesce(size, '0') AS INTEGER)) FROM stores) as attachments_size,
  12. (SELECT pg_size_pretty(SUM(CAST(coalesce(size, '0') AS INTEGER))) FROM stores) as attachments_size_human
  13. ").to_a[0]
  14. end
  15. end