统计数据库大小

sqlserver数据库

pstmt = conn.prepareStatement("USE " + dbName + "\n" + "SELECT sum(isnull(FILEPROPERTY(name, 'SpaceUsed'),0))/128 /*MB*/ size, "
                + "sum(isnull(max_size,0))/128 /*MB*/ maxsize FROM sys.database_files where name like '%_dat'");

oracle数据库

pstmt = conn.prepareStatement(
                "select a.tablespace_name, a.used_space bytes, " + "a.tablespace_size maxbytes, b.file_name " + "from sys.dba_tablespace_usage_metrics a, sys.dba_data_files b "
                    + "where a.tablespace_name = b.tablespace_name");

mysql数据库

 pstmt = conn.prepareStatement("select TABLE_SCHEMA,truncate(sum(data_length)/1024/1024,2) + truncate(sum(index_length)/1024/1024,2) as total_size " + "from information_schema.tables "
                + "where TABLE_SCHEMA not in ('mysql','information_schema','performance_schema') " + " group by TABLE_SCHEMA " + "order by total_size desc;");

猜你喜欢

转载自my.oschina.net/u/1473861/blog/1630006