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

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;

 

posted @ 2020-05-07 08:57  老孙家人  阅读(280)  评论(0)    收藏  举报