zoukankan      html  css  js  c++  java
  • postgres 查询表的大小 清空表

    查询表中数据大小:

    --数据库中单个表的大小(不包含索引)

    select pg_size_pretty(pg_relation_size('表名'));

    --查出所有表(包含索引)并排序
    SELECT table_schema || '.' || table_name AS table_full_name, pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS size
    FROM information_schema.tables
    ORDER BY
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC limit 20

    --查出表大小按大小排序并分离data与index
    SELECT
    table_name,
    pg_size_pretty(table_size) AS table_size,
    pg_size_pretty(indexes_size) AS indexes_size,
    pg_size_pretty(total_size) AS total_size
    FROM (
    SELECT
    table_name,
    pg_table_size(table_name) AS table_size,
    pg_indexes_size(table_name) AS indexes_size,
    pg_total_relation_size(table_name) AS total_size
    FROM (
    SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name
    FROM information_schema.tables
    ) AS all_tables
    ORDER BY total_size DESC
    ) AS pretty_sizes

    删除表中数据:

    1.适用数据量较小的情况

    delete from tablename;

    2.适合删除大量数据,速度快

    TRUNCATE TABLE tablename;

    3.若该表有外键,要用级联方式删所有关联的数据

    TRUNCATE TABLE tablename CASCADE;

    直接删表:

    drop table if exists +表名

  • 相关阅读:
    Linux下C语言的调试--转
    linux下c的网络编程---转载
    redis学习资料
    Keepalived配置与使用--转载
    Redis configuration
    keepalived程序包
    Keepalived 使用指南
    myeclipse解决JSP文件script调整背景颜色
    java 面试题汇总(未完成)
    c++ primer plus(文章6版本)中国版 编程练习答案第八章
  • 原文地址:https://www.cnblogs.com/pass-ion/p/15097344.html
Copyright © 2011-2022 走看看