logo
GBase 8s
运维管理
文章

大事务处理

GBase社区管理员
发表于2024-02-01 14:24:4575次浏览0个评论

巡检过程中,【onstat -x】输出可能存在以下两种场景:

场景1:

事务开始位置日志号比当前日志号小很多,且【current logpos】一直不变,如以下输出:

address          flags userthread       locks  begin_logpos      current logpos    isol    rb_time  retrys coord
4619aa38         A-B-- 46162e68         3      23:0x6018         23:0x6050         COMMIT  00:00:00 0

【onstat -l |grep C】查看当前日志位置,示例输出:

471ebbe0         8        U---C-L  28       1:600263            50000        6     0.01

当前日志已到28,事务一直停留在23:0x6050不变。

场景2:

事务开始位置日志号比当前日志号很多,且【current logpos】一直在变,如以下输出:

address          flags userthread       locks  begin_logpos      current logpos    isol    rb_time  retrys coord
4619aa38         A-B-- 46162e68         4      23:0x6018         28:0x8018         COMMIT  00:00:00 0

处理建议

以上两个场景,由于事务开始时间早,且一直未提交,可能发展为长事务,同时事务长时间不提交,也会长时间锁定操作的数据行,影响数据库并发性能。

可使用【onlog】命令查看数据库逻辑日志,来判断事务开始时间及事务操作流程:
示例:

onlog -n 23 > 23.onlog

示例输出:(在23.onlog中搜索事务开始位置【6018】)

addr     len  type     xid      id link
6018     56   BEGIN    62       23 0        01/26/2024 11:01:18 178      gbasedbt
6050     84   HINSERT  62       0  6018     200047   101      17

可以看到该事务开始时间为【01/26/2024 11:01:18】,内部事务id【xid】为62,该事务往partnum为0x200047表插入了一行数据,可使用oncheck -pt 0x200047查看对应表名,
如:

[gbasedbt@dbhost1 ~]$ oncheck -pt 0x200047



TBLspace Report for testdb:gbasedbt.t

    Physical Address               2:2288
    Creation date                  01/26/2024 10:42:58
    TBLspace Flags                 902        Row Locking
                                              TBLspace contains VARCHARS
                                              TBLspace use 4 bit bit-maps
    Maximum row size               116
    Number of special columns      1
    Number of keys                 0
    Number of extents              1
    Current serial value           1
    Current SERIAL8 value          1
    Current BIGSERIAL value        1
    Current REFID value            1
    Pagesize (k)                   16
    First extent size              4
    Next extent size               4
    Number of pages allocated      4
    Number of pages used           2
    Number of data pages           1
    Number of rows                 2
    Partition partnum              2097223
    Partition lockid               2097223

    Extents
         Logical Page     Physical Page        Size Physical Pages
                    0            2:4664           4         32

可见,该事务往t表插入了一行数据,由于onlog没有加-l参数,不显示具体插入数据,如要显示具体插入数据内容,使用以下命令:

onlog -n 23 -l > 23.onlog.l

示例输出:

addr     len  type     xid      id link
6018     56   BEGIN    62       23 0        01/26/2024 11:01:18 178      gbasedbt
         38000000 17000100 00000000 00000000 8....... ........
         00000000 00000000 3e000000 00000000 ........ >.......
         3a3f2200 00000000 7e20b365 00000000 :?"..... ~ .e....
         f4010000 b2000000                   ........
6050     84   HINSERT  62       0  6018     200047   101      17
         54000000 00002800 12410100 00000000 T.....(. .A......
         00000000 00000000 3e000000 18600000 ........ >....`..
         3a3f2200 47002000 47002000 01010000 :?".G. . G. .....
         11000000 00000000 00000000 00000000 ........ ........
         00000001 61202020 20202020 20200001 ....a          ..
         623f2200                            b?".

查看t表结构:

[gbasedbt@dbhost1 ~]$ dbschema -d testdb -t t

DBSCHEMA Schema Utility       GBASE-SQL Version 12.10.FC4G1AEE







{ TABLE "gbasedbt".t row size = 116 number of columns = 3 index size = 0 ccolnum = 0
 commcol = col1,col2,col3 }

create table "gbasedbt".t
  (
    col1 integer,
    col2 char(10),
    col3 varchar(100)
  );

revoke all on "gbasedbt".t from "public" as "gbasedbt";

逻辑日志中对应插入的数据为:(即1,'a','b')

00000001 61202020 20202020 20200001 ....a          ..
623f2200                            b?".

要查看完整的事务流程,可使用awk过滤事务中xid为62的行,且日志位置在【begin_logpos】和【current logpos】之间。
如:(该事务从6018开始,结束位置可能不在23号,在其他日志号中)

[gbasedbt@dbhost1 ~]$ awk '$4~/62/{print $0}' 23.onlog
4018     40   CLR      62       6  6f210bc
4040     56   ROLLBACK 62       6  6f210bc  01/26/2024 10:58:25
6018     56   BEGIN    62       23 0        01/26/2024 11:01:18 178      gbasedbt
6050     84   HINSERT  62       0  6018     200047   101      17

关于更多【onlog】使用及输出说明,参考【GBase 8s 管理员参考】中【2.5.2 逻辑日志记录的结构】

 

评论

登录后才可以发表评论