签到成功

知道了

CNDBA社区CNDBA社区

openGauss Astore(Append Update)和 Ustore(In-place Update)数据引擎 说明

2023-04-12 17:57 1338 0 原创 openGauss
作者: dave

1 数据引擎说明

openGauss 中有两种数据引擎:Astore(Append Update)Ustore(In-place Update)

1.1 Astore存储引擎

  Astore采用追加更新模式,即同一个page页中既存在前映像也存在当前值,只是前映像会被标记为删除。Astore是opengauss的默认存储引擎,Astore存储引擎由于同一个块中包含太多的前映像,如果频繁的更新操作会导致大量的磁盘“垃圾”,因为在执行查询操作的时候即使标记了删除也会扫描,所以大大的降低性能,建议定期执行VACUUM或者VACUUM full进行清理。http://www.cndba.cn/dave/article/116545

1.2 Ustore存储引擎

Ustore(In-place Update)存储引擎是openGauss 2.1.0版本新增的特性。此前的版本使用的行存储引擎是Append Update(追加更新)模式。追加更新对于业务中的增、删以及HOT(HeapOnly Tuple)Update(即同一页面内更新)有很好的表现,但对于跨数据页面的非HOT UPDATE场景,垃圾回收不够高效。因此,Ustore存储引擎应运而生。http://www.cndba.cn/dave/article/116545

Ustore存储引擎将最新版本的“有效数据”和历史版本的“垃圾数据”分离存储。将最新版本的“有效数据”存储在数据页面上,并单独开辟一段UNDO空间,用于统一管理历史版本的“垃圾数据”,因此数据空间不会由于频繁更新而膨胀,“垃圾数据”集中回收效率更高。Ustore存储引擎结合UNDO空间,可以实现更高效、更全面的闪回查询和回收站机制,能快速回退人为“误操作”。http://www.cndba.cn/dave/article/116545

Ustore 可以提供高性能:对插入、更新、删除等不同负载的业务,性能以及资源使用表现相对均衡。更新操作采用原地更新模式在频繁更新类的业务场景下可拥有更高、更平稳的性能表现。适应“短”(事务短)、“频”(更新操作频繁)、“快”(性能要求高)的典型OLTP类业务场景。

高效存储:支持最大限度的原位更新, 极大节约了空间;将回滚段、数据页面分离存储,具备更高效、平稳的IO使用能力,UNDO子系统采用NUMA-aware设计,具有更好的多核扩展性,UNDO空间统一分配,集中回收,复用效率更高,存储空间使用更加高效、平稳。

USTORE与原有的ASTORE(Append Update)存储引擎并存。USTORE存储引擎屏蔽了存储层实现的细节,SQL语法和原有的ASTORE存储引擎使用基本保持一致,唯一差别是建表和建索引有些细微区别。

但在opengauss 5.0.0 版本中,默认的存储引擎还是Astore。

2 示例

2.1 创建Astore 表

默认存储引擎为Astore,在不指定STORAGE_TYPE的情况下,不显示,但默认就是atore。

cndba=# create table dave(id int,name varchar2(100));
CREATE TABLE
cndba=# /d+ dave
                                 Table "public.dave"
 Column |          Type          | Modifiers | Storage  | Stats target | Description 
--------+------------------------+-----------+----------+--------------+-------------
 id     | integer                |           | plain    |              | 
 name   | character varying(100) |           | extended |              | 
Has OIDs: no
Options: orientation=row, compression=no

cndba=#

创建表时指定STORAGE_TYPE则显示:

http://www.cndba.cn/dave/article/116545
http://www.cndba.cn/dave/article/116545

cndba=# create table t2(id int,name varchar(200)) with (STORAGE_TYPE=ASTORE);
CREATE TABLE
cndba=# /d+ t2
                                  Table "public.t2"
 Column |          Type          | Modifiers | Storage  | Stats target | Description 
--------+------------------------+-----------+----------+--------------+-------------
 id     | integer                |           | plain    |              | 
 name   | character varying(200) |           | extended |              | 
Has OIDs: no
Options: orientation=row, storage_type=astore, compression=no

cndba=#

2.2 创建Ustore 对象

2.2.1 配置Ustore

USTORE存储引擎含有undo log,创建USTORE存储引擎表的时候需要提前在postgresql.conf中配置undo_zone_count的值,该参数代表内存中可分配的undo zone数量,0代表禁用undo和Ustore表,建议配置为16384,即“undo_zone_count=16384”,配置完成后要重启数据库。

[dave@www.cndba.cn ~]$ gsql -d postgres -p 15500 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:07:56 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# /c cndba
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "cndba" as user "omm".
cndba=# 
cndba=# show max_connections;
 max_connections 
-----------------
 5000
(1 row)

cndba=# show undo_zone_count;
 undo_zone_count 
-----------------
 0
(1 row)

建议取值为max_connections*4。

[dave@www.cndba.cn ~]$ gs_guc set -N all -I all -c "undo_zone_count=16384"

2.2.2 创建Ustore 表

有两种方式:http://www.cndba.cn/dave/article/116545

  1. 建表时指定storage_type。
  2. 修改用户默认的引擎。

指定storage_type=ustore:http://www.cndba.cn/dave/article/116545

cndba=# create table ustc(id int, name varchar(10)) with (storage_type=ustore);
CREATE TABLE
cndba=# /d+ ustc
                                Table "public.ustc"
 Column |         Type          | Modifiers | Storage  | Stats target | Description 
--------+-----------------------+-----------+----------+--------------+-------------
 id     | integer               |           | plain    |              | 
 name   | character varying(10) |           | extended |              | 
Has OIDs: no
Options: orientation=row, storage_type=ustore, compression=no

修改默认引擎:http://www.cndba.cn/dave/article/116545

[dave@www.cndba.cn ~]$ gs_guc set -N all -I all -c "enable_default_ustore_table=on"

重启DB:

[dave@www.cndba.cn ~]$ gs_ctl restart -D /data/openGauss/install/data/dn


cndba=# create table anqing(id int, name varchar(10));
CREATE TABLE
cndba=# /d+ anqing;
                               Table "public.anqing"
 Column |         Type          | Modifiers | Storage  | Stats target | Description 
--------+-----------------------+-----------+----------+--------------+-------------
 id     | integer               |           | plain    |              | 
 name   | character varying(10) |           | extended |              | 
Has OIDs: no
Options: orientation=row, compression=no, storage_type=USTORE

cndba=#

2.2.3 创建Ustore 索引

USTORE存储引擎使用的索引为UBtree, UBtree是专门给USTORE存储引擎开发的索引,也是该引擎目前唯一支持的索引类型。

同样也是两种方法:

http://www.cndba.cn/dave/article/116545
http://www.cndba.cn/dave/article/116545

  1. 在create 命令中指定ubtree
  2. 使用修改用户默认的引擎。

我们这里因为改过了引擎,所以这里直接创建就是ustore:

cndba=# create index ubt_idx on anqing(id);
CREATE INDEX
cndba=# /d+ anqing;
                               Table "public.anqing"
 Column |         Type          | Modifiers | Storage  | Stats target | Description 
--------+-----------------------+-----------+----------+--------------+-------------
 id     | integer               |           | plain    |              | 
 name   | character varying(10) |           | extended |              | 
Indexes:
    "ubt_idx" ubtree (id) WITH (storage_type=USTORE) TABLESPACE pg_default
Has OIDs: no
Options: orientation=row, compression=no, storage_type=USTORE

cndba=#

在create 命令中指定:

cndba=# create index ubt_idx2 on anqing using ubtree(id);
CREATE INDEX
cndba=# /d+ anqing;
                               Table "public.anqing"
 Column |         Type          | Modifiers | Storage  | Stats target | Description 
--------+-----------------------+-----------+----------+--------------+-------------
 id     | integer               |           | plain    |              | 
 name   | character varying(10) |           | extended |              | 
Indexes:
    "ubt_idx" ubtree (id) WITH (storage_type=USTORE) TABLESPACE pg_default
    "ubt_idx2" ubtree (id) WITH (storage_type=USTORE) TABLESPACE pg_default
Has OIDs: no
Options: orientation=row, compression=no, storage_type=USTORE

cndba=#

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2239
    原创
  • 3
    翻译
  • 547
    转载
  • 186
    评论
  • 访问:6658492次
  • 积分:4249
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ