postgresql - 为什么看不到我的模式大小

标签 postgresql schema postgresql-9.3

如果你用谷歌搜索“postgresql 表大小”,你会得到这个很好的查询。 https://wiki.postgresql.org/wiki/Disk_Usage

SELECT *, pg_size_pretty(total_bytes) AS total
    , pg_size_pretty(index_bytes) AS INDEX
    , pg_size_pretty(toast_bytes) AS toast
    , pg_size_pretty(table_bytes) AS TABLE
  FROM (
  SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
      SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
              , c.reltuples AS row_estimate
              , pg_total_relation_size(c.oid) AS total_bytes
              , pg_indexes_size(c.oid) AS index_bytes
              , pg_total_relation_size(reltoastrelid) AS toast_bytes
          FROM pg_class c
          LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
          WHERE relkind = 'r'
  ) a
) a;

我有一个架构 app:

enter image description here

但没有显示在结果中:

enter image description here

为什么 app schema 没有显示在结果中?

我再试一次query , 并返回空结果。

select table_name, pg_relation_size(table_name)
from information_schema.tables
where table_schema = 'app'
order by 2

最佳答案

不幸的是,即使是 psql 命令行工具也不会显示模式中所有对象的总大小。所有命令,如用于数据库的“\l+”或用于表的“\dt+”,都以“+”形式显示总大小。只有模式的“\dn+”不显示大小。

从 pg_class 中选择可能是最好的,但不要只过滤“r”——模式还包含索引和其他对象。

关于postgresql - 为什么看不到我的模式大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40977776/

相关文章:

postgresql - 为什么 char 数据类型会自动转换为 bpchar?

mysql - 在 RDBMS 中标记已删除条目的更好方法

ruby-on-rails - 如何清理 Rails 4 中的原始 SQL

postgresql - Postgres 可以区分时间戳和夏令时吗?

web-services - 对于支持 CRUD 操作的 RESTful API,我应该使用单个或多个复杂类型吗?

node.js - 在 postgresql 有线协议(protocol)中,如何从部分执行的选择中到达 ReadyForQuery?

ruby-on-rails - 简单的Form分组方法

c# - 将 xml 模式和数据加载到 DataSet(和 datagridview)中

regex - 在 JSON Schema 中使用 RegEx

postgresql - group by count查询耗时较长