首页 > 其他分享 >KingbaseES V8R6 sys_squeeze 使用

KingbaseES V8R6 sys_squeeze 使用

时间:2023-05-09 19:47:28浏览次数:32  
标签:插件 指定 sys test slots squeeze KingbaseES

sys_squeeze介绍

sys_squeeze是KingbaseES的一个扩展插件,该组件将提供人工调用命令实现对表dead tuple的清理工作。该组件在清理表空间的过程中,不会全程加排他锁,能保证业务运行期间尽可能不影响对目标表的访问。而 vacuum full也可实现死亡元组占用空间释放,但是缺点是会锁表,阻止业务进行。该插件的实现依赖于逻辑解码,因此使用该插件之前必须保证数据库wal_level等级设置为'logical'。

测试

sys_squeeze使用条件:wal_level = logical
max_replication_slots = 10 # minimum 1
shared_preload_libraries = 'sys_squeeze'
create extension sys_squeeze;

查看扩展插件

test=# \dx sys_squeeze;
                           List of installed extensions
    Name     | Version | Schema  |                  Description
-------------+---------+---------+------------------------------------------------
 sys_squeeze | 1.4     | squeeze | A tool to remove unused space from a relation.
(1 row)
创建测试表
test=# create table test(id int,c_name varchar(200),primary key(id));
CREATE TABLE

初始化数据
test=# insert into test select generate_series(1,4000000),'tom';
INSERT 0 4000000
查看表大小:169MB
TEST=# \dt+ test
                   List of relations
 Schema | Name | Type  | Owner  |  Size  | Description
--------+------+-------+--------+--------+-------------
 public | test | table | system | 138 MB |
(1 row)
使用squeeze手工清理语法:
函数接口squeeze.squeeze_table(opt1,opt2,opt3,opt4,opt5) 有5个可配置参数:

opt1: 填写所要清理的目标表的模式名,必须项

opt2: 填写所要清理的目标表名,必须项

opt3: 指定该表中已存在的index 名,若指定,会在新生成的表空间中按照此index顺序物理排列tuple,可选项,不指定填null

opt4: 指定将新生成的表置入指定的表空间。 可选项,若不指定填null,表示仍然使用原有表空间。

opt5: 将相应index置入指定的表空间。可选项,若不指定填null,表示仍然使用原有表空间。
更新数据
test=# update test set c_name = 'TRE-6' where id <2000000;
UPDATE 1999999

更新后表大小,表已膨胀
TEST=#  \dt+ test
                   List of relations
 Schema | Name | Type  | Owner  |  Size  | Description
--------+------+-------+--------+--------+-------------
 public | test | table | system | 223 MB |
(1 row)


更新数据后查看死亡元祖是1999999:
TEST=# select * from sys_stat_user_tables where relname='test';
 relid | schemaname | relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | n_tup_ins | n_tup_upd | n_tup_del | n_tup_hot_upd | n_live_tup | n_dead_tup | n_mod_since_analyze |          last_va
cuum          |        last_autovacuum        | last_analyze |       last_autoanalyze        | vacuum_count | autovacuum_count | analyze_count | autoanalyze_count
-------+------------+---------+----------+--------------+----------+---------------+-----------+-----------+-----------+---------------+------------+------------+---------------------+-----------------
--------------+-------------------------------+--------------+-------------------------------+--------------+------------------+---------------+-------------------
 25746 | public     | test    |        6 |     20000000 |        1 |       1999999 |   4000000 |   5999997 |         0 |             0 |    4000668 |    1999999 |             1999999 | 2023-04-23 16:22
:54.344454+08 | 2023-04-23 16:26:50.718373+08 |              | 2023-04-23 16:26:53.339778+08 |            1 |                2 |             0 |                 3
(1 row)


示例执行squeeze:可以看到过程中生成了new table,new index,并行relfilenode改变

TEST=# SELECT squeeze.squeeze_table('public', 'test', null, null, null);
NOTICE:  Now begin to squeeze the table.
NOTICE:  Trying to setup logical decoding.
NOTICE:  This step needs acquire lock and may be block if there is long time not ending transaction,if this step is not done in a long time(e.g. 1min) please cancel the session and try again when the transaction is end.
NOTICE:  Setup logical decoding done.
NOTICE:  Now create transient table.
NOTICE:  New table 'test' locates at [base/12145/25751]
NOTICE:  Now cp the data to new created table.
NOTICE:  Now create index on the new created table.
NOTICE:  New index 'test_pkey' locates at [base/12145/25754].
NOTICE:  Now process the concurrent changes via logical decoding.
NOTICE:  The data has been moved to new table, now release the replication slot.
NOTICE:  Now swap the filenode.
NOTICE:  Delete the old table.
NOTICE:  The squeeze process is done.
 squeeze_table
---------------

(1 row)
表膨胀占用空间已被释放
TEST=# \dt+ test
                   List of relations
 Schema | Name | Type  | Owner  |  Size  | Description
--------+------+-------+--------+--------+-------------
 public | test | table | system | 154 MB |
(1 row)
squeeze后死亡元祖已清空
TEST=# select * from sys_stat_user_tables where relname='test';
 relid | schemaname | relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | n_tup_ins | n_tup_upd | n_tup_del | n_tup_hot_upd | n_live_tup | n_dead_tup | n_mod_since_analyze |          last_va
cuum          |        last_autovacuum        | last_analyze |       last_autoanalyze        | vacuum_count | autovacuum_count | analyze_count | autoanalyze_count
-------+------------+---------+----------+--------------+----------+---------------+-----------+-----------+-----------+---------------+------------+------------+---------------------+-----------------
--------------+-------------------------------+--------------+-------------------------------+--------------+------------------+---------------+-------------------
 25746 | public     | test    |        5 |     16000000 |        1 |       1999999 |   4000000 |   3999998 |         0 |             0 |    4000668 |          0 |                   0 | 2023-04-23 16:22
:54.344454+08 | 2023-04-23 16:26:50.718373+08 |              | 2023-04-23 16:26:53.339778+08 |            1 |                2 |             0 |                 3
(1 row)

总结

sys_squeeze需要使用logical replication,所以需要设置足够的slots,而且必须注意可能与standby或者使用了逻辑复制功能争抢slots复制槽,要保证slots足够用。

虽然sys_squeeze可以自动收缩,但对于比较繁忙的数据库,建议不要在业务高峰期启用,避免对业务带来性能损耗风险。

注意sys_squeeze插件的使用条件,尤其确保表具有主键或唯一约束。这是处理sys_squeeze工作时的必要条件。

标签:插件,指定,sys,test,slots,squeeze,KingbaseES
From: https://www.cnblogs.com/kingbase/p/17370145.html

相关文章

  • KingbaseES V8R6备份恢复系列之 -- system-Id不匹配备份故障
    ​KingbaseESV8R6备份恢复案例之---system-Id不匹配备份故障案例说明:在KingbaseESV8R6执行备份时,在sys_log日志中出现system-id不一致的故障并伴随有归档失败,故障如下图所示:适用版本:KingbaseESV8R6一、问题分析1、查看当前数据库system-id可以通过sys_controldata-D......
  • KingbaseES数据库运维案例之---permission denied to create "sys_catalog.xxx"
    ​KingbaseES数据库运维案例之---permissiondeniedtocreate"sys_catalog.bdsj_bdgl_test"案例说明:在KingbaseES数据库kingbase.conf修改了search_path='"$user",sys_catalog'后,在数据库下执行创建对象操作,出现以下故障。适用版本:KingbaseESV8R6一、问题现象如下所示......
  • KingbaseES V8R6运维案例之---MySQL和KingbaseES字符串排序规则对比
    案例说明:相同数据排序后查询,在MySQL和KingbaseES下得到的排序顺序不一致,本案例从MySQL和KingbaseES的排序规则分析,两种数据库排序的异同点。适用版本:KingbaseESV8R6、MySQL8.0一、MySQL的排序规则1、排序规则(collation)排序规则是依赖于字符集,字符集是用来定义MySQL存储不......
  • KingbaseES 实现 MySQL 函数 last_insert_id
    用户从mysql迁移到金仓数据库过程中,应用中使用了mysql函数last_insert_id()来获取最近insert的那行记录的自增字段值。mysql文档中关于函数的说明和例子:LAST_INSERT_ID()如果没有参数,则LAST_INSERT_ID()返回一个BIGINTUNSIGNED(64位)值,表示AUTO_INCREMENT由于最近执行的INSERT语......
  • KingbaseES 语句like前匹配如何使用索引
    前言有现场同事反馈sql语句like使用后缀通配符%不走索引。至于执行计划没走索引的原因与KingbaseES数据库中的排序规则相关。测试测试环境:KingbaseESV8R6C7test=#\dtestTable"public.test"Column|Type|Collation|Nullable|Default--......
  • KingbaseES V8R3 集群运维系列 -- sync_flag参数配置
    ​案例说明:在KingbaseESV8R3集群一主二备的架构中,配置了流复制为同步(sync)模式,但是集群启动后,流复制状态中显示备库是async模式(备库和主库数据已经同步),从备库的recovery.log日志也可以看到,备库启动后被复制模式设置为async模式。如下图备库recovery.log:适用版本:KingbaseES......
  • KingbaseES 分区表修改字段类型
    KingbaseES普通表修改表结构请参考:KingbaseES变更表结构表重写问题数据类型转换重写与不重写:varchar(x)转换到varchar(y)当y>=x,不需要重写。numeric(x,z)转换到numeric(y,z)当y>=x,或者不指定精度类型,不需要重写。numeric(x,c)转换到numeric(y,z)当y=xc>z,当numer......
  • KingbaseES 使用sys_bulkload远程导入
    前言sys_bulkload常见场景是本地导入数据,也可以在远程运行sys_bulkload,对数据库上的CSV文件进行导入。远程导入数据时候需要注意,csv文件和ctl文件所在服务器。以下举例展示整个远程导入的过程。测试环境V8R6C7演示目的将数据从IP2所在服务器导入到IP3远程服务器上。IP3......
  • KingbaseES 复制冲突之锁类型冲突
    背景昨天遇到客户现场的一个有关复制冲突的问题备库报错:ERROR:cancelingstatementduetoconflictwithrecovery,userwasholdingarelationlockfortoolong现场情景是备库执行逻辑备份过程中出现的报错,逻辑备份相当于备库查询语句,snapshot,这时主库业务繁忙,对备库查询......
  • KingbaseES V8R6 等待事件之LWLock Buffer_IO
    等待事件含义当进程同时尝试访问相同页面时,等待其他进程完成其输入/输出(I/O)操作时,会发生LWLock:BufferIO等待事件。其目的是将同一页读取到共享缓冲区中。每个共享缓冲区都有一个与LWLock:BufferIO等待事件相关联的I/O锁,每次都必须在共享缓冲区外部检索页。此锁用于处理多个会......