This commit is contained in:
2020-06-02 19:01:36 +00:00
parent 6d7075b044
commit 6e6739cd1a

View File

@@ -209,8 +209,23 @@ namespace AyaNova.Api.Controllers
List<MetricNameLongValue> TopTables = new List<MetricNameLongValue>();
using (var command = ct.Database.GetDbConnection().CreateCommand())
{
//top 10 tables by size
command.CommandText = @"SELECT relname AS ""table_name"", pg_table_size(C.oid) AS ""table_size"" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND nspname !~ '^pg_toast' AND relkind IN ('r') ORDER BY pg_table_size(C.oid) DESC;";
/*
pg_table_size(table_name) AS table_size,
pg_indexes_size(table_name) AS indexes_size,
*/
var cmd=@"SELECT
table_name,
pg_total_relation_size(table_name) AS total_size
FROM (
SELECT ('""' || table_schema || '"".""' || table_name || '""') AS table_name
FROM information_schema.tables
where table_schema not in('pg_catalog','information_schema')
) AS all_tables
ORDER BY total_size DESC";
command.CommandText = cmd;
ct.Database.OpenConnection();
using (var dr = command.ExecuteReader())
{
@@ -220,6 +235,7 @@ namespace AyaNova.Api.Controllers
{
long tableSize = dr.GetInt64(1);
string tableName = dr.GetString(0);
tableName=tableName.Replace("\"","").Replace("public.a","");
if (tableSize > 0)
{
tableSize = tableSize / MB;