KingbaseES V8R6运维案例之---wal日志解析DDL操作
案例说明:
通过sys_waldump解析DDL操作,获取DDL操作的日志条目具体内容。
适用版本:
KingbaseES V8R3/R6
一、DDL事务操作对应的wal日志文件
# 查看当前online的wal日志文件
prod1=# select pg_current_wal_lsn(),pg_walfile_name(pg_current_wal_lsn()),pg_walfile_name_offset(pg_current_wal_lsn());
pg_current_wal_lsn | pg_walfile_name | pg_walfile_name_offset
--------------------+--------------------------+-----------------------------------
4/5C0251D8 | 0000001D000000040000005C | (0000001D000000040000005C,152024)
(1 row)
##如上所示,当前事务操作的wal日志flush到“0000001D000000040000005C”对应的日志文件。
二、sys_waldump解析wal日志
1、执行sys_waldump解析日志
[kingbase@node101 bin]$ ./sys_waldump /data/kingbase/r6ha/data/sys_wal/0000001D000000040000005C -s 4/5C003C70
2、分析“create database”操作日志
test=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/5C003C70
(1 row)
test=# create database prod1;
CREATE DATABASE
1)如下图所示,“create database”事务对应的rmgr:Database,xid:288,操作类型:create,并从template0模板创建prod1数据库(copy),数据库oid:189186。

2)rmgr:XLOG,操作类型:CHECKPOINT_ONLINE,记录checkpoint对应的日志。fpw true:开启full page write。

3)rmgr:Transaction,操作类型:commit,xid为2882的事务提交,将日志条目从wal buffer同步(sync)到磁盘。
4)rmgr:Standby记录事务的状态信息。

3、分析“ create table”操作日志
prod1=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/5C004700
(1 row)
prod1=# create table tb1 (id int,name varchar2(10));
CREATE TABLE
prod1=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/5C024788
(1 row)
1)如下所示:rmgr:Storage对应的表创建,对应的操作:Create,lsn:4/5C004730,xid:2883,filenode:base/189186/189187。

2)创建表后,将更新系统表和视图及系统表的索引。在创建表后的日志条目里记录了对系统表、视图及索引的操作。如rmgr: Heap、rmgr: Btree 等,操作类型:insert。
rmgr: Heap len (rec/tot): 56/ 6703, tx: 2883, lsn: 4/5C004760, prev 4/5C004730, desc: INSERT off 102 flags 0x01, blkref #0: rel 1663/189186/1247 blk 0 FPW
rmgr: Btree len (rec/tot): 55/ 8345, tx: 2883, lsn: 4/5C0061A8, prev 4/5C004760, desc: INSERT_LEAF off 793, blkref #0: rel 1663/189186/2703 blk 1 FPW
rmgr: Btree len (rec/tot): 55/ 11952, tx: 2883, lsn: 4/5C008260, prev 4/5C0061A8, desc: INSERT_LEAF off 715, blkref #0: rel 1663/189186/2704 blk 1 FPW
rmgr: Heap len (rec/tot): 56/ 8138, tx: 2883, lsn: 4/5C00B128, prev 4/5C008260, desc: INSERT off 243 flags 0x01, blkref #0: rel 1663/189186/2608 blk 14 FPW
rmgr: Btree len (rec/tot): 55/ 8783, tx: 2883, lsn: 4/5C00D110, prev 4/5C00B128, desc: INSERT_LEAF off 635, blkref #0: rel 1663/189186/2673 blk 11 FPW
rmgr: Btree len (rec/tot): 55/ 7976, tx: 2883, lsn: 4/5C00F378, prev 4/5C00D110, desc: INSERT_LEAF off 800, blkref #0: rel 1663/189186/2674 blk 17 FPW
rmgr: Heap len (rec/tot): 207/ 207, tx: 2883, lsn: 4/5C0112B8, prev 4/5C00F378, desc: INSERT off 103 flags 0x00, blkref #0: rel 1663/189186/1247 blk 0
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C011388, prev 4/5C0112B8, desc: INSERT_LEAF off 793, blkref #0: rel 1663/189186/2703 blk 1
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C0113C8, prev 4/5C011388, desc: INSERT_LEAF off 103, blkref #0: rel 1663/189186/2704 blk 1
rmgr: Heap len (rec/tot): 80/ 80, tx: 2883, lsn: 4/5C011410, prev 4/5C0113C8, desc: INSERT off 247 flags 0x00, blkref #0: rel 1663/189186/2608 blk 14
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C011460, prev 4/5C011410, desc: INSERT_LEAF off 635, blkref #0: rel 1663/189186/2673 blk 11
rmgr: Btree len (rec/tot): 55/ 10341, tx: 2883, lsn: 4/5C0114A8, prev 4/5C011460, desc: INSERT_LEAF off 1096, blkref #0: rel 1663/189186/2674 blk 7 FPW
rmgr: Heap len (rec/tot): 56/ 3340, tx: 2883, lsn: 4/5C013D28, prev 4/5C0114A8, desc: INSERT off 2 flags 0x01, blkref #0: rel 1663/189186/1259 blk 0 FPW
rmgr: Btree len (rec/tot): 55/ 7685, tx: 2883, lsn: 4/5C014A50, prev 4/5C013D28, desc: INSERT_LEAF off 729, blkref #0: rel 1663/189186/2662 blk 1 FPW
rmgr: Standby len (rec/tot): 46/ 46, tx: 0, lsn: 4/5C016870, prev 4/5C014A50, desc: RUNNING_XACTS nextXid 2884 latestCompletedXid 1543588432 oldestRunningXid 2883
rmgr: Btree len (rec/tot): 55/ 11364, tx: 2883, lsn: 4/5C0168A0, prev 4/5C016870, desc: INSERT_LEAF off 681, blkref #0: rel 1663/189186/2663 blk 1 FPW
rmgr: Btree len (rec/tot): 55/ 6292, tx: 2883, lsn: 4/5C019520, prev 4/5C0168A0, desc: INSERT_LEAF off 673, blkref #0: rel 1663/189186/3455 blk 1 FPW
rmgr: Heap len (rec/tot): 56/ 4147, tx: 2883, lsn: 4/5C01ADD0, prev 4/5C019520, desc: INSERT off 81 flags 0x01, blkref #0: rel 1663/189186/1249 blk 4 FPW
rmgr: Btree len (rec/tot): 55/ 5564, tx: 2883, lsn: 4/5C01BE08, prev 4/5C01ADD0, desc: INSERT_LEAF off 404, blkref #0: rel 1663/189186/2658 blk 8 FPW
rmgr: Btree len (rec/tot): 55/ 3969, tx: 2883, lsn: 4/5C01D3E0, prev 4/5C01BE08, desc: INSERT_LEAF off 359, blkref #0: rel 1663/189186/2659 blk 6 FPW
rmgr: Heap len (rec/tot): 175/ 175, tx: 2883, lsn: 4/5C01E380, prev 4/5C01D3E0, desc: INSERT off 82 flags 0x00, blkref #0: rel 1663/189186/1249 blk 4
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C01E430, prev 4/5C01E380, desc: INSERT_LEAF off 405, blkref #0: rel 1663/189186/2658 blk 8
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C01E478, prev 4/5C01E430, desc: INSERT_LEAF off 360, blkref #0: rel 1663/189186/2659 blk 6
rmgr: Heap len (rec/tot): 175/ 175, tx: 2883, lsn: 4/5C01E4B8, prev 4/5C01E478, desc: INSERT off 83 flags 0x00, blkref #0: rel 1663/189186/1249 blk 4
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C01E568, prev 4/5C01E4B8, desc: INSERT_LEAF off 404, blkref #0: rel 1663/189186/2658 blk 8
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C01E5B0, prev 4/5C01E568, desc: INSERT_LEAF off 359, blkref #0: rel 1663/189186/2659 blk 6
rmgr: Heap len (rec/tot): 175/ 175, tx: 2883, lsn: 4/5C01E5F0, prev 4/5C01E5B0, desc: INSERT off 84 flags 0x00, blkref #0: rel 1663/189186/1249 blk 4
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C01E6A0, prev 4/5C01E5F0, desc: INSERT_LEAF off 407, blkref #0: rel 1663/189186/2658 blk 8
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C01E6E8, prev 4/5C01E6A0, desc: INSERT_LEAF off 359, blkref #0: rel 1663/189186/2659 blk 6
rmgr: Heap len (rec/tot): 175/ 175, tx: 2883, lsn: 4/5C01E728, prev 4/5C01E6E8, desc: INSERT off 86 flags 0x00, blkref #0: rel 1663/189186/1249 blk 4
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C01E7D8, prev 4/5C01E728, desc: INSERT_LEAF off 404, blkref #0: rel 1663/189186/2658 blk 8
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C01E820, prev 4/5C01E7D8, desc: INSERT_LEAF off 359, blkref #0: rel 1663/189186/2659 blk 6
rmgr: Heap len (rec/tot): 175/ 175, tx: 2883, lsn: 4/5C01E860, prev 4/5C01E820, desc: INSERT off 88 flags 0x00, blkref #0: rel 1663/189186/1249 blk 4
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C01E910, prev 4/5C01E860, desc: INSERT_LEAF off 408, blkref #0: rel 1663/189186/2658 blk 8
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C01E958, prev 4/5C01E910, desc: INSERT_LEAF off 359, blkref #0: rel 1663/189186/2659 blk 6
rmgr: XLOG len (rec/tot): 49/ 491, tx: 2883, lsn: 4/5C01E998, prev 4/5C01E958, desc: FPI_FOR_HINT , blkref #0: rel 1663/189186/1249 fork fsm blk 2 FPW
rmgr: Heap len (rec/tot): 56/ 4800, tx: 2883, lsn: 4/5C01EB88, prev 4/5C01E998, desc: INSERT off 201 flags 0x01, blkref #0: rel 1663/189186/1249 blk 27 FPW
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C01FE48, prev 4/5C01EB88, desc: INSERT_LEAF off 404, blkref #0: rel 1663/189186/2658 blk 8
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C01FE90, prev 4/5C01FE48, desc: INSERT_LEAF off 359, blkref #0: rel 1663/189186/2659 blk 6
rmgr: Heap len (rec/tot): 175/ 175, tx: 2883, lsn: 4/5C01FED0, prev 4/5C01FE90, desc: INSERT off 202 flags 0x00, blkref #0: rel 1663/189186/1249 blk 27
rmgr: Btree len (rec/tot): 72/ 72, tx: 2883, lsn: 4/5C01FF80, prev 4/5C01FED0, desc: INSERT_LEAF off 409, blkref #0: rel 1663/189186/2658 blk 8
rmgr: Btree len (rec/tot): 64/ 64, tx: 2883, lsn: 4/5C01FFC8, prev 4/5C01FF80, desc: INSERT_LEAF off 359, blkref #0: rel 1663/189186/2659 blk 6
rmgr: Heap len (rec/tot): 80/ 80, tx: 2883, lsn: 4/5C020020, prev 4/5C01FFC8, desc: INSERT off 534 flags 0x00, blkref #0: rel 1663/189186/2608 blk 14
rmgr: Btree len (rec/tot): 55/ 12130, tx: 2883, lsn: 4/5C020070, prev 4/5C020020, desc: INSERT_LEAF off 712, blkref #0: rel 1663/189186/2673 blk 10 FPW
rmgr: Btree len (rec/tot): 55/ 4590, tx: 2883, lsn: 4/5C022FF0, prev 4/5C020070, desc: INSERT_LEAF off 403, blkref #0: rel 1663/189186/2674 blk 11 FPW
3)更新(update)操作前,需获取对象锁(lock),rmgr: Standby类型记录获取lock的日志条目,操作类型:Lock。

4)当表创建和系统表更新完成后,执行事务的commit。rmgr: Transaction资源类型记录事务commit操作。

5)通过wal日志记录的系统表的oid,可以获取创建表时,需要更新的系统表信息。
prod1=# select oid,relname from sys_class where oid in(1247,2703,2704,2608,2673,2674,1259,2662,2663,3455,1249,2658,2659,1249);
oid | relname
------+-----------------------------------
1247 | pg_type
2658 | pg_attribute_relid_attnam_index
2659 | pg_attribute_relid_attnum_index
2662 | pg_class_oid_index
2663 | pg_class_relname_nsp_index
3455 | pg_class_tblspc_relfilenode_index
2673 | pg_depend_depender_index
2674 | pg_depend_reference_index
2703 | pg_type_oid_index
2704 | pg_type_typname_nsp_index
1249 | pg_attribute
1259 | pg_class
2608 | pg_depend
(13 rows)

3、分析“truncate table”操作日志
prod1=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/5C0249F8
(1 row)
prod1=# truncate table tb1;
TRUNCATE TABLE
prod1=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/5C024C50
(1 row)
1)如下图所示:执行‘truncate table’需要在表上获取lock,rmgr: Standby 的资源类型记录获取锁的操作,操作类型:lock。
2)‘truncate table’资源类型:rmgr: Storage,操作类型:Create,只是原对象的filenode“base/189186/189190”被更新。
3)对系统表、视图、索引进行更新。rmgr: Heap 、rmgr: Tree,操作类型:insert、update、clean等。rmgr: Heap2资源类型,对应的操作类型:CLEAN。
4)执行事务的commit,rmgr: Transaction ,操作类型:commit,并记录commit的时间戳。

4、分析“drop table”操作日志
prod1=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/5C024C50
(1 row)
prod1=# drop table tb1;
DROP TABLE
prod1=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/5C0251D8
(1 row)
1)如下图所示:‘drop table’和‘truncate table’一样,需要获取对象lock。rmgr: Standby资源类型对应的操作:lock。
2)将对象drop后,将会delete系统表中所有的记录。rmgr: Heap,对应的操作为:DELETE

3)drop table后,完成事务的commit;rmgr: Transaction,对应的操作为:COMMIT。

5、分析“create |drop tablespace”操作日志
# 删除表空间操作
prod=# drop tablespace users;
DROP TABLESPACE
prod=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/66006700
(1 row)
# 创建自定义表空间
prod=# create tablespace user_tbs1 location '/data/kingbase/tbs/users';
CREATE TABLESPACE
prod=# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
4/66006AA8
(1 row)
test=# select oid,* from sys_tablespace where spcname='user_tbs1';
oid | oid | spcname | spcowner | spcacl | spcoptions
--------+--------+-----------+----------+--------+------------
189205 | 189205 | user_tbs1 | 10 | |
(1 row)
1)如下图所示:‘drop tablespace’对应的资源类型:rmgr: Tablespace,操作类型为:DROP,记录表空间oid。执行完成后,立刻commit。
2)记录系统表更新操作,rmgr: Heap 、Tree,操作类型:INSERT、INSERT_LEAF

3)‘create tablespace’对应的资源类型:rmgr: Tablespace,操作类型:CREATE,创建完成后,事务commit。

三、总结
通过对wal日志的解析,可以加深DDL事务操作的理解及获取事务在wal日志中的具体操作记录信息,可用于数据库事务操作的分析和数据的恢复。
KingbaseES V8R6运维案例之---wal日志解析DDL操作的更多相关文章
- KingbaseES V8R6备份恢复案例之---自定义表空间指定恢复目录数据恢复
案例说明: KingbaseES V8R6在通过sys_rman执行物理备份恢复时,可以通过参数'--kb1-path',指定恢复的数据(data)目录,但如果原备份中包含自定义表空间时,需要建立表空 ...
- 【运维工具】logrotate 日志管理神器
服务器经常会产生各种各样的日志文件,我们需要定期清理 日志的分类 系统日志 应用日志 系统日志 例如系统的history 历史信息 crontab的运行日志 一般系统日志系统都帮我们运维好了,不 ...
- Nginx-Tomcat 等运维常用服务的日志分割-logrotate
目录 一 .Nginx-Tomcat 等常用服务日志分析 Nginx 日志 Tomcat日志 MongoDB 日志 Redis 日志 二 .日志切割服务 logrotate 三.日志切割示例 Ngin ...
- KingbaseES V8R6集群管理运维案例之---repmgr standby switchover故障
案例说明: 在KingbaseES V8R6集群备库执行"repmgr standby switchover"时,切换失败,并且在执行过程中,伴随着"repmr stan ...
- KingbaseES V8R6集群运维案例之---repmgr standby promote应用案例
案例说明: 在容灾环境中,跨区域部署的异地备节点不会自主提升为主节点,在主节点发生故障或者人为需要切换时需要手动执行切换操作.若主节点已经失效,希望将异地备机提升为主节点. $bin/repmgr s ...
- KingbaseES V8R3集群运维案例之---cluster.log ERROR: md5 authentication failed
案例说明: 在KingbaseES V8R3集群的cluster.log日志中,经常会出现"ERROR: md5 authentication failed:DETAIL: password ...
- KingbaseES V8R6备份恢复案例之--删除test数据库后sys_backup.sh备份
案例说明: KingbaseES V8R6通过sys_backup.sh执行物理备份,默认sys_backup.sh执行备份初始化时,需要连接test数据库进行身份的认证:在一些生产环境为了安全需求, ...
- KingbaseES V8R6备份恢复案例之---同一数据库创建不同stanza备份
案例说明: 在生产环境,有的应用需要调用数据库的sys_rman做备份,为了区分数据库自身的sys_rman备份和应用的备份,可以使用不同的stanza name创建备份.本案例介绍了,如何在King ...
- KingbaseES V8R6备份恢复案例之---手工清理冗余历史备份
案例说明: 对于KingbaseES V8R6的通过sys_rman执行的物理历史备份,可以在执行备份时,备份的保留(retention)策略自动清理.不能通过手工删除备份,可以通过expire参数手 ...
- 网站运维工具使用iis日志分析工具分析iis日志(iis日志的配置)
我们只能通过各种系统日志来分析网站的运行状况,对于部署在IIS上的网站来说,IIS日志提供了最有价值的信息,我们可以通过它来分析网站的响应情况,来判断网站是否有性能问题,或者存在哪些需要改进的地方 对 ...
随机推荐
- maven源修改
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...
- Spring源码阅读系列--全局目录
阅读之前要注意的东西:本文就是主打流水账式的源码阅读,主导的是一个参考,主要内容需要看官自己去源码中验证.全系列文章基于 spring 源码 5.x 版本. 写在开始前的话: 阅读spring 源码实 ...
- spring事务的传播
目录 事务的传播行为类型 注意事项 关于事务的传播,我们先确定一个场景:方法A调用方法B,方法A可能存在事务,也可能不存在事务,我们这里重点关注方法B上定义的事务传播行为,以及方法B中出现异常时,方法 ...
- kafka学习笔记01-kafka简介和架构介绍
一.kafka介绍 kafka 最开始是 Linkedin 用来处理海量的日志信息,后来 linkedin 于 2010 年贡献给了 Apache 基金会并成为了顶级项目. 后来开发 kafka 的一 ...
- 像闪电般击碎天空吧——快速轻量化模型之 SDXL-Lightning
SDXL-Lightning 是一个由 ByteDance(字节跳动) 开发的文本到图像的生成模型,其主要贡献在于其高速的生成能力和轻量化的设计. 模型的特点 快速生成:SDXL-Lightning ...
- 【Azure Cloud Services】云服务频繁发生服务器崩溃的排查方案
问题描述 云服务(Cloud Services)在使用期间,频繁发生崩溃事件,在崩溃期间,查看CPU负载为100%,而且同时伴随以下情况: 部署在云服务上的应用无法访问 远程连接云服务实例(RDP)访 ...
- 如何在 C# 中以编程的方式将 CSV 转为 Excel XLSX 文件
前言 Microsoft Excel的XLSX格式以及基于文本的CSV(逗号分隔值)格式,是数据交换中常见的文件格式.应用程序通过实现对这些格式的读写支持,可以显著提升性能.在本文中,小编将为大家介绍 ...
- For 循环跟yield区别?
for循环遍历一个万亿级别的长列表,会将这个列表的全部数据载入到内存中去,如果你的内存很小就会溢出,即使是内存很大,这个操作也是十分占用资源的. 而使用生成器,则会将数据的状态(例如:遍历到列表的哪个 ...
- Java 常用类 String的常用方法(1)
1 package com.bytezero.stringclass; 2 3 import org.junit.Test; 4 5 import java.sql.SQLOutput; 6 impo ...
- Lambda表达式(匿名函数)
C++11中引入了lambda表达式,定义匿名的内联函数. 我们可以直接原地定义函数而不用再跑到外面去定义函数跳来跳去. 同时在stl的排序上也有作用. [capture] (parameters) ...