postgresql table 设置存储方式 set storage

os: centos 7.4
db: postgresql 10.10

set storage

postgres=# create table blog (id int,title text,content text,memo text);  
CREATE TABLE
postgres=# 
postgres=# \d+ blog
                                    Table "public.blog"
 Column  |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description 
---------+---------+-----------+----------+---------+----------+--------------+-------------
 id      | integer |           |          |         | plain    |              | 
 title   | text    |           |          |         | extended |              | 
 content | text    |           |          |         | extended |              | 
 memo    | text    |           |          |         | extended |              | 

postgres=# alter table blog alter title set storage main;
ALTER TABLE
postgres=# alter table blog alter content set storage external;
ALTER TABLE                                
postgres=# alter table blog alter memo set storage extended;
ALTER TABLE
postgres=# 
postgres=# \d+ blog
                                    Table "public.blog"
 Column  |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description 
---------+---------+-----------+----------+---------+----------+--------------+-------------
 id      | integer |           |          |         | plain    |              | 
 title   | text    |           |          |         | main     |              | 
 content | text    |           |          |         | external |              | 
 memo    | text    |           |          |         | extended |              | 

plain:避免压缩或行外存储。
main:允许压缩,不允许行外存储。
external:允许行外存储,不允许压缩。
extended:允许压缩和行外存储。

SET STORAGE
这种形式为一列设置存储模式。这会控制这列是会被保持在线内还是放在一个 二级TOAST表中,以及数据是否应被压缩。
对于 integer之类的定长、线内、未压缩值必须使用 PLAIN。
MAIN用于线内、可压缩的 数据。
EXTERNAL用于外部的、未压缩数据。
而 EXTENDED用于外部的、压缩数据。对于大部分支持 非-PLAIN存储的数据类型,EXTENDED 是默认值。
使用EXTERNAL将会让很大的 text和bytea之上的子串操作运行得更快, 但是代价是存储空间会增加。注意SET STORAGE本身并不改变 表中的任何东西,它只是设置在未来的表更新时要追求的策略。

参考:
http://postgres.cn/docs/10/sql-altertable.html
http://postgres.cn/docs/10/storage-toast.html

发布了710 篇原创文章 · 获赞 70 · 访问量 49万+

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/104057094