PostgreSQL - 确定列存储类型

时间:2018-04-20 18:14:06

标签: postgresql

我一直在阅读有关PostgreSQL TOAST的很多内容,而且我似乎缺少一件事。他们在文档中提到,"有四种不同的策略可以在磁盘上存储TOAST-capable列,"那些是:PLAIN,EXTENDED,EXTERNAL和MAIN。他们还有一种非常明确的方法来定义您的列使用哪种策略,可以找到here。基本上,它会是这样的:

ALTER TABLE table_name ALTER COLUMN column_name SET STORAGE EXTERNAL

我不知道的一件事是如何轻松检索该设置。我的问题是,是否有一种简单的方法(通过命令或pgAdmin)来检索列使用的存储策略?

2 个答案:

答案 0 :(得分:4)

存储pg_attribute.attstorage,例如:

select att.attname, 
       case att.attstorage
          when 'p' then 'plain'
          when 'm' then 'main'
          when 'e' then 'external'
          when 'x' then 'extended'
       end as attstorage
from pg_attribute att  
  join pg_class tbl on tbl.oid = att.attrelid   
  join pg_namespace ns on tbl.relnamespace = ns.oid   
where tbl.relname = 'table_name'
  and ns.nspname = 'public'
  and not att.attisdropped;

请注意attstorage仅在attlen为>时有效。 -1

答案 1 :(得分:1)

虽然我喜欢@ a_horse_with_no_name的方法,但在发布此问题后,我将搜索范围扩展为通用表信息,发现如果使用psql,则可以使用here描述的命令,结果将是列出所有列,其类型,修饰符,存储类型,统计信息目标和描述的表。

因此,使用psql可以找到以下信息:

\d+ table_name

我想我会发布这个以防万一有人想要另一种解决方案。

相关问题