zoukankan      html  css  js  c++  java
  • postgres 表和库等信息大小统计

    一 .数据库大小的统计

    1.单个库查询

    select pg_database_size('zybdb');

    2.查询所有的库

     方法一:

    select pg_database.datname, pg_size_pretty (pg_database_size(pg_database.datname)) AS size from pg_database;

    方法二:

    SELECT d.datname AS Name,  pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
        CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')  THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
            ELSE 'No Access'   END AS SIZE
    FROM pg_catalog.pg_database d
        ORDER BY    CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')     THEN pg_catalog.pg_database_size(d.datname)    ELSE NULL  END DESC  

    二 数据库表大小查询

    所有表方法一:

    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 WHERE table_schema='cas_it'
    ORDER BY pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') desc;

    所有表方法二:

    SELECT relname,pg_size_pretty(pg_relation_size(relid))
    FROM pg_stat_user_tables WHERE schemaname='cas_it' ORDER BY pg_size_pretty(pg_relation_size(relid)) DESC

    单个表方法一:

    select pg_relation_size('cas_it.t4');

    单个表方法二:

    select pg_size_pretty(pg_total_relation_size('cas_it.t4'));

    三 查询索引大小

    select
    schemaname,
    relname,
    indexrelname,
    pg_size_pretty(pg_relation_size(indexrelid))
    from pg_stat_user_indexes
    where schemaname = 'cas_it'
    order by pg_relation_size(indexrelid) desc;

  • 相关阅读:
    UIPickerView
    visual studio2010生成get方法和set方法快捷键
    vmware安装mac虚拟机键盘失灵解决方法
    运行android模拟器过大
    [SQL Utility] How to retrieve Oracle’s version info?
    【读书笔记】c# in depth (1)
    [Oracle 10g] About Recycle bin
    [Oracle Troubleshooting] Get Oracle Bounces When Data File Is Missing
    [Oracle Mgmt]Clone Oracle Database Manually
    [SQL*PLUS]Set Up Sql*Plus
  • 原文地址:https://www.cnblogs.com/hello-wei/p/10383814.html
Copyright © 2011-2022 走看看