-
Notifications
You must be signed in to change notification settings - Fork 1
/
databases.sql
37 lines (36 loc) · 1.03 KB
/
databases.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
CREATE DATABASE IF NOT EXISTS ops;
CREATE VIEW ops.databases AS
SELECT
database
, tables
, size
, marks_size
, pk_memory
, pk_memory_allocated
, data_path
, metadata_path
, engine
FROM (
SELECT
database
, COUNT(DISTINCT table) AS tables
, SUM(bytes) AS order_size
, formatReadableSize(SUM(bytes)) AS size
, formatReadableSize(SUM(marks_size)) AS marks_size
, formatReadableSize(SUM(primary_key_bytes_in_memory)) AS pk_memory
, formatReadableSize(SUM(primary_key_bytes_in_memory_allocated)) AS pk_memory_allocated
FROM system.parts
WHERE active
GROUP BY
database
WITH TOTALS
ORDER BY order_size DESC
) AS P
INNER JOIN (
SELECT
name AS database
, data_path
, metadata_path
, engine
FROM system.databases
) AS D USING (database);