def get_stats_size(self):
stats_size = LazyStruct()
from django.db import connection
cursor = connection.cursor()
if 'postgres' in connection.settings_dict['ENGINE']:
stats_size.row_count = stats_size.data = stats_size.index = 0
for model in Stats:
cursor.execute("select count(id) as rows, pg_relation_size('{0}') as data_length, pg_total_relation_size('{0}') - pg_relation_size('{0}') as index_length from {0}".format(model._meta.db_table))
rows, data, index = cursor.fetchone()
stats_size.row_count += rows
stats_size.data += data
stats_size.index += index
else:
raise RuntimeError("Unsupported DB: %s" % connection.settings_dict['ENGINE'])
return stats_size
评论列表
文章目录