資料庫(表)檢視表大小和索引所佔記憶體空間

2021-10-10 19:53:41 字數 2234 閱讀 8495

use information_schema;

# 正序

select table_schema as

'庫名'

, table_name as

'表名'

,round

(data_length/

1024

/1024)as

'表大小(m)'

from

tables

order

by 表大小(m);

# 逆序

select table_schema as

'庫名'

, table_name as

'表名'

,round

(data_length/

1024

/1024)as

'表大小(m)'

from

tables

order

by 表大小(m) desc

;# 取排名前10

select table_schema as

'庫名'

, table_name as

'表名'

,round

(data_length/

1024

/1024)as

'表大小(m)'

from

tables

order

by 表大小(m) desc

limit1,

10;# 取排名前10,保留兩位小數(四捨五入)

select table_schema as

'庫名'

, table_name as

'表名'

,round

(data_length/

1024

/1024,2

)as'表大小(m)'

from

tables

order

by 表大小(m) desc

limit1,

10;

use information_schema;

# 查詢所有資料庫的資料量大小

select table_schema as

'庫名'

, table_name as

'表名'

,round

(sum

(data_length/

1024

/1024))

as'表大小(m)'

from

tables

group

by table_schema;

# 查詢所有資料庫容量大小,並排序

select table_schema as

'庫名'

,round

(sum

(data_length/

1024

/1024))

as'庫大小(m)'

from

tables

group

by table_schema;

# 查詢所有資料庫容量大小,顯示資料量最多的前十個庫

select table_schema as

'庫名'

,round

(sum

(data_length/

1024

/1024))

as'庫大小(m)'

from

tables

group

by table_schema desc

limit

10;

use information_schema;

select table_schema as

'庫名'

,round

(sum

(data_length/

1024

/1024))

as'庫大小(m)'

from

tables

;

select  table_name,

round

(index_length/

1024

/1024,2

)as'索引記憶體(m)'

from

tables

where table_schema =

《庫名》

;

檢視mysql資料庫所佔空間大小

select concat round sum data length 1024 1024 sum index length 1024 1024 m from information schema.tables where table schema database name 由於資料太大了。所以m...

MySQL 檢視資料庫所佔空間大小

在mysql中會有乙個預設的資料庫 information schema,裡面有乙個tables表記錄了所有表的資訊。使用該錶來看資料庫所佔空間大小的 如下 use information schema select table schema,sum data length from tables ...

PG裡如何檢視表,索引,表空間,資料庫大小

查詢乙個索引大小 select pg size pretty pg relation size indexname 檢視一張表及此它上的索引總大小 select pg size pretty pg total relation size tablename 檢視所有 schema裡面索引大小,大到小...