查看各个数据库表大小 (不包含索引) ,以及表数据量

mysql;

SELECT
    table_name,
    concat(
        round((DATA_LENGTH / 1024 / 1024), 2),
        M
    ) AS size,
    table_rows
FROM
    information_schema. TABLES
ORDER BY
    table_rows DESC

postgresql;

SELECT
    table_schema,
    TABLE_NAME,
    reltuples,
    pg_size_pretty (
        pg_total_relation_size (
            " || table_schema || "." || table_name || "
        )
    )
FROM
    pg_class,
    information_schema. TABLES
WHERE
    relname = TABLE_NAME
ORDER BY
    reltuples DESC

oracle;

-- 查记录条数可以用如下语句: 
SELECT
    *  from user_tables t
WHERE
    t.NUM_ROWS IS NOT NULL
ORDER BY
    t.NUM_ROWS DESC;

-- 表实际使用的空间:
SELECT
    num_rows * avg_row_len
FROM
    user_tables;

 

查看各个数据库表大小 (不包含索引) ,以及表数据量

上一篇:50个SQL语句(MySQL版) 问题五


下一篇:pg数据库下的基本命令