-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcapacity.py
More file actions
23 lines (20 loc) · 1.03 KB
/
Copy pathcapacity.py
File metadata and controls
23 lines (20 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import dbconnection
# fill data info array by hand or see how to get data from information_schema.tables at 'splitTbale.py'
tidb = []
tbl = []
# eg. SELECT concat(ROUND(SUM(data_length+index_length)/1024/1024/1024,2),'GB')
# FROM information_schema.tables WHERE table_schema='db3' and TABLE_NAME = 'tb1';
for i in range(0, len(tbl)):
tbl_name = tbl[i]
db_name = tidb[i]
sql = "SELECT CONCAT(ROUND(SUM(data_length)/1024/1024/1024,3),'GB') AS data_cap, " \
"CONCAT(ROUND(SUM(index_length)/1024/1024/1024,3),'GB') AS index_cap " \
"FROM INFORMATION_SCHEMA.TABLES WHERE table_schema IN (" + "'"+db_name.lower() +"'"+","+"'"+db_name.upper()+"'"+")" + \
" AND TABLE_NAME IN (" + "'" + tbl_name.lower() + "'" + "," + "'" + tbl_name.upper() + "'" + ")"+";"
connection = dbconnection.getconnection(db_name)
cursor = connection.cursor()
cursor.execute(sql)
tidb_rows = cursor.fetchall()
for row in tidb_rows:
print(db_name+"."+tbl_name, row['data_cap'], row['index_cap'])
connection.close()