【问题标题】:why cant see my schema size为什么看不到我的架构大小
【发布时间】:2017-04-20 01:17:45
【问题描述】:

如果你用谷歌搜索“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

但没有显示在结果中:

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

我尝试第二个query,也返回空结果。

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

【问题讨论】:

  • app 不包含任何表格。如果是这样,您会在结果中看到它们。
  • @NickBarnes 你说得对,应用只有功能和类型。

标签: postgresql schema postgresql-9.3


【解决方案1】:

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

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

【讨论】:

  • 问题不是架构中的对象,是架构完全丢失
  • 因为你从 pg_class 中选择,它只包含“r = 普通表,i = 索引,S = 序列,v = 视图,m = 物化视图,c = 复合类型,t = TOAST 表, f = 外部表” - 请参见此处postgresql.org/docs/current/static/catalog-pg-class.html。过程在 pg_proc 中列出,在 pg_type 中列出类型
  • 嗯,我又看了一遍你的回答,好像你说的一样,但那天我没听懂。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-26
  • 2016-04-19
  • 2021-07-21
  • 1970-01-01
  • 2021-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多